Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --prune-wordlists option #78

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ RSpec/MultipleExpectations:
RSpec/NamedSubject:
Enabled: false

RSpec/NestedGroups:
Enabled: false


# This matches the style we've been using all along (ever so slightly more frequently)
Style/Alias:
Expand Down
75 changes: 8 additions & 67 deletions .spellr_wordlists/english.txt
Original file line number Diff line number Diff line change
@@ -1,59 +1,41 @@
abc
addable
alnum
arg
arglist
args
backports
baz
behaviour
beihang
bundler
capfile
changelog
charpos
cli
cmd
codebase
codebases
colours
config
configs
css
ctrl
customisations
cyclomatic
def
desaturate
dict
diffable
diffs
docker
dockerfile
dockerhub
dockerignore
downloader
editmsg
elp
entrya
entryb
entryc
entryd
entrye
entryf
entryg
env
eos
eot
eplace
erb
ercim
esque
exclusions
exe
executables
exitstatus
ext
filename
filenames
foo
gemfile
gemspec
getch
git
github
gitignore
gitignored
Expand All @@ -64,104 +46,66 @@ gtm
haml
hardcoded
hashbang
hashbangs
hashbangs
heuristically
hml
hostnames
href
htt
hyperwallet
i'll
i'm
ico
inclusions
ise
ize
javascript
jbuilder
jpg
jruby
json
jsx
keio
keydata
keypress
khz
klass
kwargs
localhost
logstash
lstripped
mailto
marketplacer
matcher
matchers
maths
mdn
memoized
merchantability
multibyte
multiline
newlines
noninfringement
nonwords
notaword
num
optparse
org
param
params
png
prg
punycode
pwd
rakefile
rdoc
readme
redisplay
regexps
repo
rspec
rubocop
rubygems
rvm
scss
sendgrid
shelljoin
shellsplit
shellwords
sherson
simplecov
stderr
stdin
stdlib
stdout
str
stringscanner
strscan
struct
sublicense
subwords
subcommand
sudo
superselector
svg
symlinks
thu
tlds
tmp
todo
tokenize
tokenizer
tokenizes
tsx
ttf
txt
unitless
unrecognised
unscan
uploader
uri
urls
usr
utf
Expand All @@ -170,12 +114,9 @@ wai
webpack
woff
wordlist
wordlists
wordn't
wtf
xdescribe
xit
xlsx
yardoc
yml
zsh
3 changes: 0 additions & 3 deletions .spellr_wordlists/lorem.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
amet
dolar
dolares
dolor
elp
eplace
ipsum
lorem
6 changes: 0 additions & 6 deletions .spellr_wordlists/ruby.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
cov
kwarg
matchdata
nocov
nokogiri
pty
rubo
simplecov
subclasses
vars
webmock
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# v0.10.0
- add `spellr --prune-wordlists` to remove unused terms.

# v0.9.1
- Assume all files are utf8, more comprehensively. (Sets ::Encoding.default_external and default_internal while running)
- Assume all files are utf8, more comprehensively. (Sets `::Encoding.default_external` and `.default_internal` while running)

# v0.9.0
- Recognize url with _ in query string and zero length path
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ $ spellr --wordlist '*.rb' '*_test.js'
There are some support commands available:

```bash
$ spellr --prune-wordlists # after succeeding, remove unused words from the .spellr_wordlists/ files
$ spellr --dry-run # list files that will be checked
$ spellr --version # for the current version
$ spellr --help # for the list of flags available
Expand Down
21 changes: 14 additions & 7 deletions lib/spellr/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,33 @@ def initialize(argv)
end

def run
catch(:spellr_exit) { check }
catch(:spellr_exit) { run_subcommand }
rescue Spellr::Error => e
Spellr.config.output.warn(Spellr::StringFormat.red(e.message)) && 1
Spellr.config.output.warn(Spellr::StringFormat.red(e.message))
1
end

private

def check
def run_subcommand
CLI::Options.parse(@argv)
Spellr.config.valid?
checker = Spellr.config.checker.new(files: files)
exit_code = check
exit_code = prune if exit_code.zero? && Spellr.config.prune_wordlists?
exit_code
end

def check
checker = Spellr.config.checker.new(files: Spellr.config.file_list)
checker.check

checker.exit_code
end

def files
require_relative 'file_list'
Spellr::FileList.new(@argv)
def prune
require_relative 'prune'
Spellr.config.output.puts ''
Spellr::Prune.run
end
end
end
17 changes: 14 additions & 3 deletions lib/spellr/cli_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def parse(argv)
@parallel_option = false

options.parse!(argv)

Spellr.config.file_list_patterns = argv
end

private
Expand All @@ -20,17 +22,20 @@ def parse(argv)
def options # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
opts = OptionParser.new

opts.banner = 'Usage: spellr [options] [files]'
opts.banner = 'Usage: spellr [options] [file patterns]'
opts.separator('')
opts.on('-w', '--wordlist', 'Outputs errors in wordlist format', &method(:wordlist_option))
opts.on('-q', '--quiet', 'Silences output', &method(:quiet_option))
opts.on('-i', '--interactive', 'Runs the spell check interactively', &method(:interactive_option))
opts.separator('')
opts.on('--[no-]parallel', 'Run in parallel or not, default --parallel', &method(:parallel_option))
opts.on('-d', '--dry-run', 'List files to be checked', &method(:dry_run_option))
opts.on('-f', '--suppress-file-rules', <<~HELP, &method(:suppress_file_rules))
opts.on('-f', '--suppress-file-rules', <<~HELP, &method(:suppress_file_rules_option))
Suppress all configured, default, and gitignore include and exclude patterns
HELP
opts.on('--prune-wordlists', <<~HELP, &method(:prune_wordlists_option))
Prune unused words from .spellr_wordlists/*.txt after checking.
HELP
opts.separator('')
opts.on('-c', '--config FILENAME', String, <<~HELP, &method(:config_option))
Path to the config file (default ./.spellr.yml)
Expand All @@ -49,6 +54,8 @@ def wordlist_option(_)

def quiet_option(_)
require_relative 'quiet_reporter'
require_relative 'output_stubbed'
Spellr.config.output = Spellr::OutputStubbed.new
Spellr.config.reporter = Spellr::QuietReporter.new
end

Expand All @@ -59,10 +66,14 @@ def interactive_option(_)
Spellr.config.checker = Spellr::CheckInteractive unless @parallel_option
end

def suppress_file_rules(_)
def suppress_file_rules_option(_)
Spellr.config.suppress_file_rules = true
end

def prune_wordlists_option(_)
Spellr.config.prune_wordlists = true
end

def config_option(file)
file = Spellr.pwd.join(file).expand_path

Expand Down
12 changes: 10 additions & 2 deletions lib/spellr/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

module Spellr
class Config
attr_writer :reporter, :checker
attr_writer :reporter, :checker, :output

attr_accessor :suppress_file_rules, :dry_run
attr_accessor :suppress_file_rules, :dry_run, :prune_wordlists, :file_list_patterns

attr_reader :config_file
alias_method :dry_run?, :dry_run
alias_method :prune_wordlists?, :prune_wordlists

def initialize
@config = ConfigLoader.new
Expand Down Expand Up @@ -88,6 +89,13 @@ def reset! # rubocop:disable Metrics/MethodLength
remove_instance_variable(:@key_minimum_length) if defined?(@key_minimum_length)
end

def file_list
@file_list ||= begin
require_relative 'file_list'
Spellr::FileList.new(file_list_patterns)
end
end

private

def dry_run_checker
Expand Down
Loading