Skip to content

Commit

Permalink
Add check for --auto-correct with --disable-uncorrectable
Browse files Browse the repository at this point in the history
The `--disable-uncorrectable` flag should not be given on its own. Only with
`--auto-correct`.
  • Loading branch information
jonas054 authored and bbatsov committed Jul 16, 2019
1 parent c9f71dc commit ec6b538
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/rubocop/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def initialize(options)
@options = options
end

# rubocop:disable Metrics/AbcSize
def validate_compatibility # rubocop:disable Metrics/MethodLength
if only_includes_unneeded_disable?
raise OptionArgumentError, 'Lint/UnneededCopDisableDirective can not ' \
Expand All @@ -272,13 +273,15 @@ def validate_compatibility # rubocop:disable Metrics/MethodLength
'--display-only-fail-level-offenses'
end
validate_auto_gen_config
validate_auto_correct
validate_parallel

return if incompatible_options.size <= 1

raise OptionArgumentError, 'Incompatible cli options: ' \
"#{incompatible_options.inspect}"
end
# rubocop:enable Metrics/AbcSize

def validate_auto_gen_config
return if @options.key?(:auto_gen_config)
Expand All @@ -294,6 +297,15 @@ def validate_auto_gen_config
end
end

def validate_auto_correct
return if @options.key?(:auto_correct)
return unless @options.key?(:disable_uncorrectable)

raise OptionArgumentError,
format('--%<flag>s can only be used together with --auto-correct.',
flag: '--disable-uncorrectable')
end

def validate_parallel
return unless @options.key?(:parallel)

Expand Down
12 changes: 12 additions & 0 deletions spec/rubocop/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,18 @@ def abs(path)
end
end

describe '--disable-uncorrectable' do
it 'accepts together with --auto-correct' do
expect { options.parse %w[--auto-correct --disable-uncorrectable] }
.not_to raise_error
end

it 'fails if given alone without --auto-correct/-a' do
expect { options.parse %w[--disable-uncorrectable] }
.to raise_error(RuboCop::OptionArgumentError)
end
end

describe '--exclude-limit' do
it 'fails if given last without argument' do
expect { options.parse %w[--auto-gen-config --exclude-limit] }
Expand Down

0 comments on commit ec6b538

Please sign in to comment.