From 0bc7b80cb06e1c1abd6b7026b2ec7a2c88309be7 Mon Sep 17 00:00:00 2001 From: Jonas Arvidsson Date: Sun, 19 Apr 2020 08:41:20 +0200 Subject: [PATCH] [Fix #7881] Call act_on_options earlier in CLI#run() This fixes another problem that's similar to the one reported in #7790. The problem is still that configuration is read and cached when we validate options vs configuration. By acting on all options first, we make sure that the first time we read configuration, it's done according to the given options. Specifically, it's the --force-default-config option that's now being respected. --- CHANGELOG.md | 1 + lib/rubocop/cli.rb | 5 +++-- spec/rubocop/cli/cli_options_spec.rb | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0106851936f..0ae0b4fc8ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * [#7882](https://github.com/rubocop-hq/rubocop/pull/7882): Fix `Style/CaseEquality` when `AllowOnConstant` is `true` and the method receiver is implicit. ([@rafaelfranca][]) * [#7790](https://github.com/rubocop-hq/rubocop/issues/7790): Fix `--parallel` and `--ignore-parent-exclusion` combination. ([@jonas054][]) +* [#7881](https://github.com/rubocop-hq/rubocop/issues/7881): Fix `--parallel` and `--force-default-config` combination. ([@jonas054][]) ### Changes diff --git a/lib/rubocop/cli.rb b/lib/rubocop/cli.rb index 030043bc6c6..3ad675f23d4 100644 --- a/lib/rubocop/cli.rb +++ b/lib/rubocop/cli.rb @@ -35,9 +35,8 @@ def run(args = ARGV) if @options[:init] run_command(:init) else - set_options_to_config_loader - validate_options_vs_config act_on_options + validate_options_vs_config apply_default_formatter execute_runners end @@ -84,6 +83,8 @@ def validate_options_vs_config end def act_on_options + set_options_to_config_loader + @config_store.options_config = @options[:config] if @options[:config] @config_store.force_default_config! if @options[:force_default_config] diff --git a/spec/rubocop/cli/cli_options_spec.rb b/spec/rubocop/cli/cli_options_spec.rb index bca6206f797..64ab95cda6a 100644 --- a/spec/rubocop/cli/cli_options_spec.rb +++ b/spec/rubocop/cli/cli_options_spec.rb @@ -66,6 +66,20 @@ expect($stdout.string).to match(/Inspecting 1 file/) end end + + context 'in combination with --force-default-config' do + before do + create_file('.rubocop.yml', ['ALLCOPS:', # Faulty configuration + ' Exclude:', + ' - subdir/*']) + create_file('test.rb', 'puts 1') + end + + it 'does not parse local configuration' do + cli.run ['--parallel', '--force-default-config'] + expect($stdout.string).to match(/Inspecting 1 file/) + end + end end end