Skip to content

Commit

Permalink
[Fix rubocop#10536] Fix validation for command-line options combinati…
Browse files Browse the repository at this point in the history
…on of `--display-only-fail-level-offenses` and `--auto-correct`
  • Loading branch information
nobuyo committed Apr 29, 2022
1 parent 5f526f7 commit 789a4cc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/fix_validation_for_commandline_options.md
@@ -0,0 +1 @@
* [#10536](https://github.com/rubocop/rubocop/issues/10536): Fix validation for command-line options combination of `--display-only-fail-level-offenses` and `--auto-correct`. ([@nobuyo][])
5 changes: 3 additions & 2 deletions lib/rubocop/options.rb
Expand Up @@ -309,7 +309,7 @@ def validate_compatibility # rubocop:disable Metrics/MethodLength
end

if display_only_fail_level_offenses_with_autocorrect?
raise OptionArgumentError, '--autocorrect cannot be used with ' \
raise OptionArgumentError, '--auto-correct cannot be used with ' \
'--display-only-fail-level-offenses'
end

Expand Down Expand Up @@ -402,7 +402,8 @@ def only_includes_redundant_disable?
end

def display_only_fail_level_offenses_with_autocorrect?
@options[:display_only_fail_level_offenses] && @options[:autocorrect]
@options[:display_only_fail_level_offenses] &&
(@options.key?(:auto_correct) || @options.key?(:safe_auto_correct))
end

def except_syntax?
Expand Down
9 changes: 9 additions & 0 deletions spec/rubocop/options_spec.rb
Expand Up @@ -290,6 +290,15 @@ def abs(path)
end
end

describe '--display-only-fail-level-offenses' do
it 'fails if given with --auto-correct' do
%w[--auto-correct -a --auto-correct-all -A].each do |o|
expect { options.parse ['--display-only-correctable', o] }
.to raise_error(RuboCop::OptionArgumentError)
end
end
end

describe '--display-only-correctable' do
it 'fails if given with --display-only-failed' do
expect { options.parse %w[--display-only-correctable --display-only-failed] }
Expand Down

0 comments on commit 789a4cc

Please sign in to comment.