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

Respect DisabledByDefault for custom cops #7013

Merged
merged 2 commits into from
May 15, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

### Bug fixes

* [#7013](https://github.com/rubocop-hq/rubocop/pull/7013): Respect DisabledByDefault for custom cops. ([@XrXr][])
* [#7043](https://github.com/rubocop-hq/rubocop/issues/7043): Prevent RDoc error when installing RuboCop 0.69.0 on Ubuntu. ([@koic][])

## 0.69.0 (2019-05-13)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ def enable_cop?(qualified_cop_name, cop_options)
end
end

cop_options.fetch('Enabled', true)
cop_options.fetch('Enabled') { !for_all_cops['DisabledByDefault'] }
end

def smart_loaded_path
Expand Down
34 changes: 34 additions & 0 deletions spec/rubocop/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,40 @@ def cop_enabled(cop_class)
expect(cop_enabled(cop_class)).to be true
end
end

context 'when configuration has no mention of a cop' do
let(:hash) do
{}
end

it 'enables the cop that is not mentioned' do
expect(cop_enabled('VeryCustomDepartment/CustomCop')).to be true
end

context 'when all cops are disabled by default' do
let(:hash) do
{
'AllCops' => { 'DisabledByDefault' => true }
}
end

it 'disables the cop that is not mentioned' do
expect(cop_enabled('VeryCustomDepartment/CustomCop')).to be false
end
end

context 'when all cops are explicitly enabled by default' do
let(:hash) do
{
'AllCops' => { 'EnabledByDefault' => true }
}
end

it 'enables the cop that is not mentioned' do
expect(cop_enabled('VeryCustomDepartment/CustomCop')).to be true
end
end
end
end

describe '#target_rails_version' do
Expand Down