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

Don't load exclusions from personal files when passing a config with a custom name #8239

Merged
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 @@ -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
4 changes: 4 additions & 0 deletions docs/modules/ROOT/pages/configuration.adoc
Expand Up @@ -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
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