Permalink
Browse files

Added --spell-minimum-word-length option, defaults to 4

Added total misspellings count.

Added more words from spellchecking ruby
  • Loading branch information...
1 parent 7accf81 commit 9a2abecb0ce27dc441ce342172739911917860bb @drbrain drbrain committed Apr 7, 2012
Showing with 149 additions and 7 deletions.
  1. +123 −7 lib/rdoc/generator/spellcheck.rb
  2. +26 −0 test/test_rdoc_generator_spellcheck.rb
@@ -27,6 +27,8 @@ class RDoc::Generator::Spellcheck
API
ArgumentError
CGI
+ DES
+ ECDSA
EOFError
ERb
Encoding::CompatibilityError
@@ -135,28 +137,72 @@ class RDoc::Generator::Spellcheck
Errno::NOERROR
Exception
FIXME
+ FQDN
FiberError
FileUtils
FloatDomainError
GPL
+ IETF
IOError
IndexError
Interrupt
KeyError
LoadError
LocalJumpError
+ MSDN
Math::DomainError
+ NTFS
NUL
NameError
NoMemoryError
NoMethodError
NoMethodError
NotImplementedError
+ O'Reilly
PHP
+ PNG
+ POSIX
+ PRNG
README
RangeError
RegexpError
RuntimeError
+ SIGABRT
+ SIGALRM
+ SIGBUS
+ SIGCHLD
+ SIGCLD
+ SIGCONT
+ SIGEMT
+ SIGEXIT
+ SIGFPE
+ SIGHUP
+ SIGILL
+ SIGINFO
+ SIGINT
+ SIGIO
+ SIGIOT
+ SIGKILL
+ SIGPIPE
+ SIGPROF
+ SIGQUIT
+ SIGSEGV
+ SIGSTOP
+ SIGSYS
+ SIGTERM
+ SIGTRAP
+ SIGTSTP
+ SIGTTIN
+ SIGTTOU
+ SIGURG
+ SIGUSR1
+ SIGUSR2
+ SIGVTALRM
+ SIGWINCH
+ SIGXCPU
+ SIGXFSZ
+ SMTP
+ SMTPS
ScriptError
SecurityError
SignalException
@@ -170,7 +216,9 @@ class RDoc::Generator::Spellcheck
ThreadError
TypeError
URI
+ UUCP
VCS
+ Wikipedia
XHTML
ZeroDivisionError
Zlib
@@ -179,25 +227,53 @@ class RDoc::Generator::Spellcheck
argf
argv
ary
+ authenticators
baz
bom
+ bzip
+ canonicalization
cfg
cpp
crlf
+ cryptographic
+ csh
+ daemonizing
+ decrypt
+ decrypted
+ decrypter
+ decrypting
+ decrypts
deprecations
+ dereferenced
+ deserialization
+ deserialize
+ deserialized
+ deserializes
+ deserializing
dev
+ druby
+ dRuby
dup
+ duplexed
elsif
emacs
encodings
+ encrypter
endian
env
erb
+ finalized
+ finalizer
+ finalizers
globals
gsub
+ gzip
+ gzipped
http
https
img
+ incrementing
+ initializer
inlining
instantiation
irb
@@ -211,18 +287,29 @@ class RDoc::Generator::Spellcheck
lookup
lossy
mailto
+ matz
mktmpdir
natively
newb
+ nonces
perl
popup
+ proleptic
+ proxied
pwd
racc
+ radian
+ radians
radix
rbw
redistributions
refactor
refactored
+ reinitializes
+ resized
+ rhtml
+ rsync
+ serializable
startup
stderr
stdin
@@ -234,15 +321,21 @@ class RDoc::Generator::Spellcheck
tokenizer
tokenizes
txt
+ unbuffered
unescape
unescapes
uniq
unmaintained
+ unmarshal
+ unmarshalled
+ unmarshalling
unordered
+ untagged
untrusted
utf
validator
validators
+ versioning
visibilities
www
yacc
@@ -253,6 +346,8 @@ class RDoc::Generator::Spellcheck
SpellLanguage = Object.new
+ attr_accessor :minimum_word_length # :nodoc:
+
attr_reader :spell # :nodoc:
##
@@ -261,10 +356,11 @@ class RDoc::Generator::Spellcheck
def self.setup_options options
default_language, = ENV['LANG'].split '.'
- options.spell_add_words = false
- options.spell_language = default_language
- options.spell_source_dir = Dir.pwd
- options.quiet = true # suppress statistics
+ options.spell_add_words = false
+ options.spell_language = default_language
+ options.spell_minimum_word_length = 4
+ options.spell_source_dir = Dir.pwd
+ options.quiet = true # suppress statistics
op = options.option_parser
@@ -316,14 +412,23 @@ def self.setup_options options
"The default language is #{default_language}") do |language|
options.spell_language = language
end
+
+ op.separator nil
+
+ op.on('--spell-minimum-word-length=LENGTH', Integer,
+ 'Minimum length of a word to spell check.',
+ "The default is #{options.spell_minimum_word_length}") do |length|
+ options.spell_minimum_word_length = length
+ end
end
def initialize options # :not-new:
@options = options
- @encoding = @options.encoding
- @source_dir = @options.spell_source_dir
- @aggregate_all = @options.spell_aggregate_all
+ @encoding = @options.encoding
+ @aggregate_all = @options.spell_aggregate_all
+ @minimum_word_length = @options.spell_minimum_word_length
+ @source_dir = @options.spell_source_dir
@misspellings = Hash.new 0
@@ -358,6 +463,7 @@ def find_misspelled comment
report = []
comment.text.scan(/\p{L}[\p{L}']+\p{L}/i) do |word|
+ next if $&.length < @minimum_word_length
offset = $`.length # store
word = $` if word =~ /'s$/i
@@ -433,6 +539,11 @@ def generate files
order.each do |word, count|
puts "%*d %s" % [num_width, count, word]
end
+
+ total = @misspellings.values.inject :+
+
+ puts
+ puts "Total misspellings: #{total}"
end
end
@@ -589,6 +700,11 @@ class RDoc::Options
attr_accessor :spell_language
+ ##
+ # The minimum length of a word for spell checking.
+
+ attr_accessor :spell_minimum_word_length
+
##
# The directory spellcheck was run from which contains all the source files.
@@ -18,6 +18,7 @@ def setup
@SC = RDoc::Generator::Spellcheck
@options = RDoc::Options.new
@options.spell_language = 'en_US'
+ @options.spell_minimum_word_length = 3
@sc = @SC.new @options
@@ -61,8 +62,10 @@ def test_class_setup_options_default
refute options.spell_add_words
refute options.spell_aggregate_all
+ assert_equal 4, options.spell_minimum_word_length
assert_equal 'en_US', options.spell_language
assert_equal Dir.pwd, options.spell_source_dir
+
assert options.quiet
ensure
ENV['LANG'] = orig_lang
@@ -137,6 +140,18 @@ def test_class_setup_options_spell_language
assert_equal 'en_GB', options.spell_language
end
+ def test_class_setup_options_spell_minimum_word_length
+ options = RDoc::Options.new
+
+ options.parse %w[
+ --format spellcheck
+ --no-ignore-invalid
+ --spell-minimum-word-length 5
+ ]
+
+ assert_equal 5, options.spell_minimum_word_length
+ end
+
def test_initialize_add_words
private_wordlist do
@options.spell_add_words = %w[funkify thingus]
@@ -175,6 +190,17 @@ def test_find_misspelled
end
end
+ def test_find_misspelled_length
+ private_wordlist do
+ c = comment @text
+
+ @sc.minimum_word_length = 4
+ report = @sc.find_misspelled c
+
+ assert_empty report
+ end
+ end
+
def test_find_misspelled_quote
c = comment "doesn't"

0 comments on commit 9a2abec

Please sign in to comment.