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

- old
+ new

@@ -1,8 +1,7 @@ require 'ffi/hunspell' require 'set' -require 'yard' module YARD module Spellcheck # # Handles loading and spellchecking YARD Documentation. @@ -11,24 +10,27 @@ # YARD tags to not spellcheck. SKIP_TAGS = Set['example', 'since', 'see', 'api'] # The Regexp to use for scanning in words. - WORD_REGEXP = /[^\W_][[^\W_]'-]*[^\W_]/ + WORD_REGEXP = /[^\W_][\w'-]*[^\W_]/ + # The Regexp to filter out Acronyms. + ACRONYM_REGEXP = /(([A-Z]\.){2,}|[A-Z]{2,})/ + + # The Regexp to filter out CamelCase words. + CAMEL_CASE_REGEXP = /([A-Z][a-z]+){2,}/ + # The language to spellcheck against. attr_accessor :lang # The words to ignore. attr_reader :ignore # The words to add to the dictionary. attr_reader :added - # The known words from the documentation. - attr_reader :known - # The misspelled words. attr_reader :misspelled # # Initializes the spellchecker. @@ -56,11 +58,10 @@ if options[:add] @added += options[:add] end - @known = Set[] @misspelled = Hash.new { |hash,key| hash[key] = 0 } end # # Spellchecks the YARD Documentation. @@ -85,18 +86,12 @@ # load the YARD cache YARD::Registry.load! # clear any statistics from last run - @known.clear @misspelled.clear - # load known Class and Module names - YARD::Registry.all(:class, :module).each do |obj| - obj.path.split('::').each { |name| @known << name } - end - FFI::Hunspell.dict(@lang) do |dict| # add user specified words @added.each { |word| dict.add(word) } unless names.empty? @@ -165,10 +160,14 @@ # def spellcheck(text,dict) typos = Set[] text.scan(WORD_REGEXP).each do |word| - next if (@known.include?(word) || @ignore.include?(word)) + # ignore all underscored names + next if word.include?('_') + + # ignore all acronyms and CamelCase words + next if (word =~ ACRONYM_REGEXP || word =~ CAMEL_CASE_REGEXP) if (@misspelled.has_key?(word) || !dict.valid?(word)) @misspelled[word] += 1 typos << word