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 calculation of cop department for nested departments #9258

Merged
merged 1 commit into from Dec 20, 2020
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/fix_fix_calculation_of_cop_department_for.md
@@ -0,0 +1 @@
* [#9258](https://github.com/rubocop-hq/rubocop/pull/9258): Fix calculation of cop department for nested departments. ([@mvz][])
6 changes: 3 additions & 3 deletions lib/rubocop/config.rb
Expand Up @@ -292,10 +292,10 @@ def enable_cop?(qualified_cop_name, cop_options)
end

def department_of(qualified_cop_name)
cop_department, cop_name = qualified_cop_name.split('/')
return nil if cop_name.nil?
*cop_department, _ = qualified_cop_name.split('/')
return nil if cop_department.empty?

self[cop_department]
self[cop_department.join('/')]
end
end
end
Expand Down
16 changes: 16 additions & 0 deletions spec/rubocop/config_spec.rb
Expand Up @@ -781,6 +781,22 @@ def cop_enabled(cop_class)
end
end

context 'when an nested cop department is disabled' do
context 'but an individual cop is enabled' do
let(:hash) do
{
'Foo/Bar' => { 'Enabled' => false },
'Foo/Bar/BazCop' => { 'Enabled' => true }
}
end

it 'still disables the cop' do
cop_class = 'Foo/Bar/BazCop'
expect(cop_enabled(cop_class)).to be false
end
end
end

context 'when an entire cop department is enabled' do
context 'but an individual cop is disabled' do
let(:hash) do
Expand Down