From ba0fb2addccd44752e2bf117b161ccd83475dbf8 Mon Sep 17 00:00:00 2001 From: Dana Sherson Date: Sat, 15 Aug 2020 10:21:45 +1000 Subject: [PATCH] Add --suppress-file-rules Entirely for .git/COMMIT_EDITMSG though i imagine there will be other uses goes toward: #44 and is an alternative to #58 --- .spellr_wordlists/english.txt | 1 + README.md | 12 ++++++++++++ lib/spellr/cli_options.rb | 7 +++++++ lib/spellr/config.rb | 3 ++- lib/spellr/file_list.rb | 12 ++++++++++-- spec/feature_spec.rb | 14 ++++++++++++++ spec/file_list_spec.rb | 36 +++++++++++++++++++++++++++++++++++ 7 files changed, 82 insertions(+), 3 deletions(-) diff --git a/.spellr_wordlists/english.txt b/.spellr_wordlists/english.txt index a59b174..dfb0f3e 100644 --- a/.spellr_wordlists/english.txt +++ b/.spellr_wordlists/english.txt @@ -33,6 +33,7 @@ dockerfile dockerhub dockerignore downloader +editmsg elp env eos diff --git a/README.md b/README.md index c062c42..22a245d 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/spellr/cli_options.rb b/lib/spellr/cli_options.rb index 24dcea8..6bdf48c 100644 --- a/lib/spellr/cli_options.rb +++ b/lib/spellr/cli_options.rb @@ -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) @@ -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 diff --git a/lib/spellr/config.rb b/lib/spellr/config.rb index 3108a8d..cbe4978 100644 --- a/lib/spellr/config.rb +++ b/lib/spellr/config.rb @@ -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 diff --git a/lib/spellr/file_list.rb b/lib/spellr/file_list.rb index 1427273..2539400 100644 --- a/lib/spellr/file_list.rb +++ b/lib/spellr/file_list.rb @@ -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 diff --git a/spec/feature_spec.rb b/spec/feature_spec.rb index 2acdaf0..eb9bdb4 100644 --- a/spec/feature_spec.rb +++ b/spec/feature_spec.rb @@ -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 @@ -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') diff --git a/spec/file_list_spec.rb b/spec/file_list_spec.rb index cccda74..7b81f07 100644 --- a/spec/file_list_spec.rb +++ b/spec/file_list_spec.rb @@ -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