Skip to content

Commit

Permalink
Added --spell-minimum-word-length option, defaults to 4
Browse files Browse the repository at this point in the history
Added total misspellings count.

Added more words from spellchecking ruby
  • Loading branch information
drbrain committed Apr 7, 2012
1 parent 7accf81 commit 9a2abec
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 7 deletions.
130 changes: 123 additions & 7 deletions lib/rdoc/generator/spellcheck.rb
Expand Up @@ -27,6 +27,8 @@ class RDoc::Generator::Spellcheck
API
ArgumentError
CGI
DES
ECDSA
EOFError
ERb
Encoding::CompatibilityError
Expand Down Expand Up @@ -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
Expand All @@ -170,7 +216,9 @@ class RDoc::Generator::Spellcheck
ThreadError
TypeError
URI
UUCP
VCS
Wikipedia
XHTML
ZeroDivisionError
Zlib
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -253,6 +346,8 @@ class RDoc::Generator::Spellcheck

SpellLanguage = Object.new

attr_accessor :minimum_word_length # :nodoc:

attr_reader :spell # :nodoc:

##
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.

Expand Down
26 changes: 26 additions & 0 deletions test/test_rdoc_generator_spellcheck.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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"

Expand Down

0 comments on commit 9a2abec

Please sign in to comment.