Skip to content

Commit

Permalink
Don't load exclusions from personal files when passing a config with …
Browse files Browse the repository at this point in the history
…custom name

If passing a configuration with a custom name, like `rubocop
--config-file .my_custom_project_config.yml`, that configuration should
act as the project configuration and we want personal configuration
files disregarded.

That's actually the only case where `find_files_upwards` can return an
empty list, because when given an existing `.rubocop.yml` as the
starting point, it will at least return that file, and the fallback to
personal config files will not be applied.

Well, there's another case where `find_files_upwards` could return an
empty list, which is when giving it a non existent file as the starting
point. However, I don't think that ever happens in real life, and in
tests it was only happening once, and due to a typo I believe.

So, we can completely remove the explicit fallback to look for
exclusions in personal configuration files.
  • Loading branch information
deivid-rodriguez authored and bbatsov committed Jul 7, 2020
1 parent 05feb76 commit a743015
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion lib/rubocop/config_loader.rb
Expand Up @@ -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) ==
Expand Down
29 changes: 28 additions & 1 deletion spec/rubocop/config_loader_spec.rb
Expand Up @@ -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' }

Expand Down Expand Up @@ -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' }

Expand Down

0 comments on commit a743015

Please sign in to comment.