diff --git a/CHANGELOG.md b/CHANGELOG.md index 8df42ba20a0..3576749bba4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Bug fixes * [#8252](https://github.com/rubocop-hq/rubocop/issues/8252): Fix a command line option name from `--safe-autocorrect` to `--safe-auto-correct`, which is compatible with RuboCop 0.86 and lower. ([@koic][]) +* [#8239](https://github.com/rubocop-hq/rubocop/pull/8239): Don't load `.rubocop.yml` from personal folders to check for exclusions if given a custom configuration file. ([@deivid-rodriguez][]) ## 0.87.0 (2020-07-06) diff --git a/docs/modules/ROOT/pages/configuration.adoc b/docs/modules/ROOT/pages/configuration.adoc index 9fb44942b10..efa060ebff7 100644 --- a/docs/modules/ROOT/pages/configuration.adoc +++ b/docs/modules/ROOT/pages/configuration.adoc @@ -51,6 +51,10 @@ files: * `~/.config/rubocop/config.yml` * https://github.com/rubocop-hq/rubocop/blob/master/config/default.yml[RuboCop's default configuration] +All the previous logic does not apply if a specific configuration file is passed +on the command line through the `--config` flag. In that case, the resolved +configuration file will be the one passed to the CLI. + == Inheritance All configuration inherits from https://github.com/rubocop-hq/rubocop/blob/master/config/default.yml[RuboCop's default configuration] (See diff --git a/lib/rubocop/config_loader.rb b/lib/rubocop/config_loader.rb index 1188ec0c233..d8044bfe3f2 100644 --- a/lib/rubocop/config_loader.rb +++ b/lib/rubocop/config_loader.rb @@ -119,7 +119,6 @@ def possible_new_cops?(config) def add_excludes_from_files(config, config_file) 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 020e452531a..e9cef8f3d97 100644 --- a/spec/rubocop/config_loader_spec.rb +++ b/spec/rubocop/config_loader_spec.rb @@ -170,6 +170,33 @@ end end + context 'when configuration has a custom name' do + let(:file_path) { '.custom_rubocop.yml' } + + before do + create_file(file_path, <<~YAML) + AllCops: + Exclude: + - vendor/** + YAML + 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 let(:file_path) { '.rubocop.yml' } @@ -965,7 +992,7 @@ class Loop < Cop end context 'when a file inherits from a url inheriting from another file' do - let(:file_path) { '.robocop.yml' } + let(:file_path) { '.rubocop.yml' } let(:cache_file) { '.rubocop-http---example-com-rubocop-yml' } let(:cache_file_2) { '.rubocop-http---example-com-inherit-yml' }