lib/yard/spellcheck/checker.rb in yard-spellcheck-0.1.1 vs lib/yard/spellcheck/checker.rb in yard-spellcheck-0.1.2

- old
+ new

@@ -39,14 +39,14 @@ # Additional options. # # @option options [String, Symbol] :lang (FFI::Hunspell.lang) # The language to spellcheck against. # - # @option options [Array, Set] :ignore + # @option options [Array<String>, Set<String>] :ignore # The words to ignore. # - # @option options [Array, Set] :add + # @option options [Array<String>] :add # The words to add to the dictionary. # def initialize(options={}) @lang = options.fetch(:lang,FFI::Hunspell.lang) @ignore = Set[] @@ -90,11 +90,11 @@ # clear any statistics from last run @misspelled.clear FFI::Hunspell.dict(@lang) do |dict| # add user specified words - @added.each { |word| dict.add(word) } + @added.each { |word| dict.add(word.dup) } unless names.empty? names.each do |name| if (obj = YARD::Registry.at(name)) spellcheck_object(obj,dict,&block) @@ -159,20 +159,28 @@ # The misspelled words from the text. # def spellcheck(text,dict) typos = Set[] - text.scan(WORD_REGEXP).each do |word| - # ignore all underscored names - next if word.include?('_') + text.each_line do |line| + # ignore indented lines + next if line =~ /^\s{2,}/ - # ignore all acronyms and CamelCase words - next if (word =~ ACRONYM_REGEXP || word =~ CAMEL_CASE_REGEXP) + line.scan(WORD_REGEXP).each do |word| + # ignore all underscored names + next if word.include?('_') - if (@misspelled.has_key?(word) || !dict.valid?(word)) - @misspelled[word] += 1 + # ignore all acronyms and CamelCase words + next if (word =~ ACRONYM_REGEXP || word =~ CAMEL_CASE_REGEXP) - typos << word + # skip ignored words + next if @ignore.include?(word) + + if (@misspelled.has_key?(word) || !dict.valid?(word)) + @misspelled[word] += 1 + + typos << word + end end end return typos end