Skip to content

Commit

Permalink
Add --suppress-file-rules
Browse files Browse the repository at this point in the history
Entirely for .git/COMMIT_EDITMSG though i imagine there will be other
uses

goes toward: #44 and is an alternative to #58
  • Loading branch information
robotdana committed Aug 15, 2020
1 parent f58fae1 commit ba0fb2a
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 3 deletions.
1 change: 1 addition & 0 deletions .spellr_wordlists/english.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dockerfile
dockerhub
dockerignore
downloader
editmsg
elp
env
eos
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,18 @@ Spellr::RakeTask.generate_task(:spellr, **spellr_arguments)
task default: :spellr
```

## Ignoring the configured patterns

Sometimes you'll want to spell check something that would usually be ignored,
e.g. `.git/COMMIT_EDITMSG` even though `spellr` ignores the `.git` directory.

For this you can use the `--suppress-file-rules` command line argument.
```bash
$ spellr --suppress-file-rules .git/COMMIT_EDITMSG
```

**Note: This still ignores files outside of the current directory**

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
Expand Down
7 changes: 7 additions & 0 deletions lib/spellr/cli_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def options # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
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))
Suppress all configured, default, and gitignore include and exclude patterns
HELP
opts.separator('')
opts.on('-c', '--config FILENAME', String, <<~HELP, &method(:config_option))
Path to the config file (default ./.spellr.yml)
Expand Down Expand Up @@ -56,6 +59,10 @@ def interactive_option(_)
Spellr.config.checker = Spellr::CheckInteractive unless @parallel_option
end

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

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

Expand Down
3 changes: 2 additions & 1 deletion lib/spellr/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ module Spellr
class Config
attr_writer :reporter, :checker

attr_accessor :suppress_file_rules, :dry_run

attr_reader :config_file
attr_accessor :dry_run
alias_method :dry_run?, :dry_run

def initialize
Expand Down
12 changes: 10 additions & 2 deletions lib/spellr/file_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,18 @@ def to_a

private

def configured_rules
return { gitignore: false } if Spellr.config.suppress_file_rules

{
ignore_rules: Spellr.config.excludes,
include_rules: Spellr.config.includes
}
end

def fast_ignore # rubocop:disable Metrics/MethodLength
FastIgnore.new(
ignore_rules: Spellr.config.excludes,
include_rules: Spellr.config.includes,
**configured_rules,
argv_rules: @patterns,
follow_symlinks: true,
root: Spellr.pwd_s
Expand Down
14 changes: 14 additions & 0 deletions spec/feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
--[no-]parallel Run in parallel or not, default --parallel
-d, --dry-run List files to be checked
-f, --suppress-file-rules Suppress all configured, default, and gitignore include and exclude patterns
-c, --config FILENAME Path to the config file (default ./.spellr.yml)
-v, --version Returns the current version
Expand Down Expand Up @@ -483,6 +484,19 @@
)
end

it 'returns the list of files including otherwise excluded files when --suppress-file-rules' do
stub_fs_file '.git/COMMIT_EDITMSG'
spellr('--dry-run --suppress-file-rules')

expect(stderr).to be_empty
expect(exitstatus).to eq 0
expect(stdout.each_line.to_a).to contain_exactly(
"lib/bar.rb\n",
"foo.md\n",
".git/COMMIT_EDITMSG\n"
)
end

it 'can combine dry-run with no-parallel (by not being parallel in the firsts place)' do
spellr('--dry-run --no-parallel')

Expand Down
36 changes: 36 additions & 0 deletions spec/file_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,40 @@
)
end
end

context 'with excluded files and suppressing those files' do
before { stub_config(excludes: ['foo.rb', '*.txt'], suppress_file_rules: true) }

it 'ignores excluded files' do
expect(described_class.new.to_a).to match_relative_paths(
'foo.rb',
'foo/bar.txt',
'spec/foo_spec.rb'
)
end
end

context 'with suppressing default exclusions files' do
before { stub_config(suppress_file_rules: true) }

it 'ignores excluded files' do
stub_fs_file '.git/COMMIT_EDITMSG'

expect(described_class.new('.git/COMMIT_EDITMSG').to_a).to match_relative_paths(
'.git/COMMIT_EDITMSG'
)
end
end

context 'without suppressing default exclusions files' do
before { stub_config(suppress_file_rules: false) }

it 'ignores excluded files' do
stub_fs_file '.git/COMMIT_EDITMSG'

expect(described_class.new('.git/COMMIT_EDITMSG').to_a).not_to match_relative_paths(
'.git/COMMIT_EDITMSG'
)
end
end
end

0 comments on commit ba0fb2a

Please sign in to comment.