From 2362fe73470dff475cd9975a9e1b0dff8a0f6e3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Tue, 23 Jun 2020 20:18:57 +0200 Subject: [PATCH] [Fix #7433] User vs project exclusion inheritance Don't load personal configuration files to look for exclusions if there's a project configuration. --- CHANGELOG.md | 1 + lib/rubocop/config_loader.rb | 4 ++-- spec/rubocop/config_loader_spec.rb | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 118d5226254..ca262610a60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/rubocop/config_loader.rb b/lib/rubocop/config_loader.rb index d0f488c07a6..1188ec0c233 100644 --- a/lib/rubocop/config_loader.rb +++ b/lib/rubocop/config_loader.rb @@ -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) == diff --git a/spec/rubocop/config_loader_spec.rb b/spec/rubocop/config_loader_spec.rb index 6fd73a5e01b..ec4b45c0b24 100644 --- a/spec/rubocop/config_loader_spec.rb +++ b/spec/rubocop/config_loader_spec.rb @@ -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