Skip to content

Commit

Permalink
[Fix #7433] User vs project exclusion inheritance
Browse files Browse the repository at this point in the history
Don't load personal configuration files to look for exclusions if
there's a project configuration.
  • Loading branch information
deivid-rodriguez committed Jul 4, 2020
1 parent e1cbfa5 commit 2362fe7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -18,6 +18,7 @@
* [#8193](https://github.com/rubocop-hq/rubocop/issues/8193): Fix a false positive for `Style/RedundantRegexpCharacterClass` when using `[\b]`. ([@owst][])
* [#8205](https://github.com/rubocop-hq/rubocop/issues/8205): Fix a false positive for `Style/RedundantRegexpCharacterClass` when using a leading escaped `]`. ([@owst][])
* [#8208](https://github.com/rubocop-hq/rubocop/issues/8208): Fix `Style/RedundantParentheses` with hash literal as first argument to `yield`. ([@karlwithak][])
* [#8176](https://github.com/rubocop-hq/rubocop/pull/8176): Don't load `.rubocop.yml` from personal folders to check for exclusions if there's a project configuration. ([@deivid-rodriguez][])

### Changes

Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/config_loader.rb
Expand Up @@ -118,8 +118,8 @@ def possible_new_cops?(config)
end

def add_excludes_from_files(config, config_file)
found_files = find_files_upwards(DOTFILE, config_file) +
[find_user_dotfile, find_user_xdg_config].compact
found_files = find_files_upwards(DOTFILE, config_file)
found_files = [find_user_dotfile, find_user_xdg_config].compact if found_files.empty?

return if found_files.empty?
return if PathUtil.relative_path(found_files.last) ==
Expand Down
15 changes: 15 additions & 0 deletions spec/rubocop/config_loader_spec.rb
Expand Up @@ -153,6 +153,21 @@
excludes = configuration_from_file['AllCops']['Exclude']
expect(excludes).to eq([File.expand_path('vendor/**')])
end

context 'and there is a personal config file in the home folder' do
before do
create_file('~/.rubocop.yml', <<~YAML)
AllCops:
Exclude:
- tmp/**
YAML
end

it 'ignores personal AllCops/Exclude' do
excludes = configuration_from_file['AllCops']['Exclude']
expect(excludes).to eq([File.expand_path('vendor/**')])
end
end
end

context 'when a parent file specifies DisabledByDefault: true' do
Expand Down

0 comments on commit 2362fe7

Please sign in to comment.