lib/tasks/spellcheck_task.rb in yast-rake-0.2.5 vs lib/tasks/spellcheck_task.rb in yast-rake-0.2.6
- old
+ new
@@ -138,22 +138,42 @@
# spell check each line separately so we can report error locations properly
lines = File.read(file).split("\n")
success = true
lines.each_with_index do |text, index|
- misspelled = speller.list_misspelled([text]) - config["dictionary"]
+ misspelled = misspelled_on_line(text)
next if misspelled.empty?
success = false
- misspelled.each { |word| text.gsub!(word, Rainbow(word).red) } if colorize?
- puts "#{file}:#{index + 1}: \"#{text}\""
-
- misspelled.each { |word| puts " #{word.inspect} => #{speller.suggest(word)}" }
- puts
+ print_misspelled(misspelled, index, text)
end
success
end
+
+ def print_misspelled(list, index, text)
+ list.each { |word| text.gsub!(word, Rainbow(word).red) } if colorize?
+ puts "#{file}:#{index + 1}: \"#{text}\""
+
+ list.each { |word| puts " #{word.inspect} => #{speller.suggest(word)}" }
+ puts
+ end
+
+ def misspelled_on_line(text)
+ switch_block_tag if block_line?(text)
+ return [] if inside_block
+ speller.list_misspelled([text]) - config["dictionary"]
+ end
+
+ def block_line?(line)
+ line =~ /^\s*```/
+ end
+
+ def switch_block_tag
+ @inside_block = !@inside_block
+ end
+
+ attr_reader :inside_block
# run the task
def run_task
if files_to_check.all? { |file| check_file(file) }
puts "Spelling OK."