Skip to content

Commit

Permalink
[Fix #7790] Set options in ConfigLoader earlier
Browse files Browse the repository at this point in the history
Transferring options to the ConfigLoader must be done before we
validate the --parallel flag against configuration. Since we cache
the configuration when reading it to perform validation, the
cached configuration will not take all the given options into
account, which leads to different behavior when running the actual
inspection if the --parallel flag is given.
  • Loading branch information
jonas054 committed Apr 18, 2020
1 parent c4ce01c commit 617bee2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@
### Bug fixes

* [#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][])

### Changes

Expand Down
3 changes: 1 addition & 2 deletions lib/rubocop/cli.rb
Expand Up @@ -35,6 +35,7 @@ def run(args = ARGV)
if @options[:init]
run_command(:init)
else
set_options_to_config_loader
validate_options_vs_config
act_on_options
apply_default_formatter
Expand Down Expand Up @@ -83,8 +84,6 @@ 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]

Expand Down
19 changes: 19 additions & 0 deletions spec/rubocop/cli/cli_options_spec.rb
Expand Up @@ -47,6 +47,25 @@
expect($stdout.string).not_to match(/Running parallel inspection/)
end
end

context 'in combination with --ignore-parent-exclusion' do
before do
create_file('.rubocop.yml', ['AllCops:',
' Exclude:',
' - subdir/*'])
create_file('subdir/.rubocop.yml', ['AllCops:',
' Exclude:',
' - foobar'])
create_file('subdir/test.rb', 'puts 1')
end

it 'does ignore the exclusion in the parent directory configuration' do
Dir.chdir('subdir') do
cli.run ['--parallel', '--ignore-parent-exclusion']
end
expect($stdout.string).to match(/Inspecting 1 file/)
end
end
end
end

Expand Down

0 comments on commit 617bee2

Please sign in to comment.