Skip to content

Commit

Permalink
Auto disable parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
rrosenblum-splunk committed Apr 13, 2021
1 parent 02c555a commit 72abc6a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 24 deletions.
1 change: 1 addition & 0 deletions changelog/change_auto_disable_parallel.md
@@ -0,0 +1 @@
* [#9647](https://github.com/rubocop/rubocop/pull/9647): The parallel flag will now be automatically ignored when combined with `--auto-correct`, `--auto-gen-config`, or `-F/--fail-fast`. Previously, an error was raised and execution stopped. ([@rrosenblum][])
23 changes: 13 additions & 10 deletions lib/rubocop/options.rb
Expand Up @@ -343,21 +343,24 @@ def validate_parallel
'false is not allowed.'
end

validate_parallel_with_combo_option
disable_parallel_when_invalid_combo
end

def validate_parallel_with_combo_option
def disable_parallel_when_invalid_combo
combos = {
auto_gen_config: '-P/--parallel uses caching to speed up execution, ' \
'while --auto-gen-config needs a non-cached run, ' \
'so they cannot be combined.',
fail_fast: '-P/--parallel cannot be combined with -F/--fail-fast.',
auto_correct: '-P/--parallel cannot be combined with --auto-correct.'
auto_gen_config: '--auto-gen-config',
fail_fast: '-F/--fail-fast.',
auto_correct: '--auto-correct.'
}

combos.each do |key, msg|
raise OptionArgumentError, msg if @options.key?(key)
end
invalid_combos = combos.select { |key, _flag| @options.key?(key) }

return if invalid_combos.empty?

@options.delete(:parallel)

puts '-P/--parallel is being ignored because ' \
"it is not compatible with #{invalid_combos.values.join(', ')}"
end

def only_includes_redundant_disable?
Expand Down
3 changes: 3 additions & 0 deletions lib/rubocop/rake_task.rb
Expand Up @@ -68,6 +68,9 @@ def setup_subtasks(name, *args, &task_block)
RakeFileUtils.verbose(verbose) do
yield(*[self, task_args].slice(0, task_block.arity)) if task_block
options = full_options.unshift('--auto-correct-all')
# `parallel` will automatically be removed from the options internally.
# This is a nice to have to supress the warning message
# about parallel and auto-corrent not being compatible.
options.delete('--parallel')
run_cli(verbose, options)
end
Expand Down
38 changes: 24 additions & 14 deletions spec/rubocop/options_spec.rb
Expand Up @@ -208,28 +208,38 @@ def abs(path)
end

context 'combined with --auto-correct' do
it 'fails with an error message' do
msg = '-P/--parallel cannot be combined with --auto-correct.'
expect { options.parse %w[--parallel --auto-correct] }
.to raise_error(RuboCop::OptionArgumentError, msg)
it 'ignores parallel' do
msg = '-P/--parallel is being ignored because it is not compatible with --auto-correct'
options.parse %w[--parallel --auto-correct]
expect($stdout.string).to include(msg)
expect(options.instance_variable_get('@options').keys).not_to include(:parallel)
end
end

context 'combined with --auto-gen-config' do
it 'fails with an error message' do
msg = '-P/--parallel uses caching to speed up execution, while ' \
'--auto-gen-config needs a non-cached run, so they cannot be ' \
'combined.'
expect { options.parse %w[--parallel --auto-gen-config] }
.to raise_error(RuboCop::OptionArgumentError, msg)
it 'ignore parallel' do
msg = '-P/--parallel is being ignored because it is not compatible with --auto-gen-config'
options.parse %w[--parallel --auto-gen-config]
expect($stdout.string).to include(msg)
expect(options.instance_variable_get('@options').keys).not_to include(:parallel)
end
end

context 'combined with --fail-fast' do
it 'fails with an error message' do
msg = '-P/--parallel cannot be combined with -F/--fail-fast.'
expect { options.parse %w[--parallel --fail-fast] }
.to raise_error(RuboCop::OptionArgumentError, msg)
it 'ignores parallel' do
msg = '-P/--parallel is being ignored because it is not compatible with -F/--fail-fast'
options.parse %w[--parallel --fail-fast]
expect($stdout.string).to include(msg)
expect(options.instance_variable_get('@options').keys).not_to include(:parallel)
end
end

context 'combined with --auto-correct and --fail-fast' do
it 'ignores parallel' do
msg = '-P/--parallel is being ignored because it is not compatible with -F/--fail-fast'
options.parse %w[--parallel --fail-fast --auto-correct]
expect($stdout.string).to include(msg)
expect(options.instance_variable_get('@options').keys).not_to include(:parallel)
end
end
end
Expand Down

0 comments on commit 72abc6a

Please sign in to comment.