Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #7433] User vs project exclusion inheritance #8176

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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