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
Conversation
7f4dea3
to
c7390bd
Compare
lib/rubocop/config.rb
Outdated
@@ -710,7 +710,10 @@ def enable_cop?(qualified_cop_name, cop_options) | |||
end | |||
end | |||
|
|||
cop_options.fetch('Enabled', true) | |||
cop_options.fetch('Enabled') do | |||
disabled_by_default = for_all_cops['DisabledByDefault'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you can simplify this to simply !for_all_cops['DisabledByDefault']
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I opted for the verbose version because it looked nicer to me. Changed
The changes look good, but your branch has to be rebased on top of the current |
5e833cb
to
54b25c7
Compare
CHANGELOG.md
Outdated
@@ -9,7 +9,7 @@ | |||
* Add support for subclassing using `Class.new` to `Lint/InheritException`. ([@houli][]) | |||
* [#6779](https://github.com/rubocop-hq/rubocop/issues/6779): Add new cop `Style/NegativeUnless` that checks for unless with negative condition. ([@tejasbubane][]) | |||
* [#6649](https://github.com/rubocop-hq/rubocop/pull/6649): Layout/AlignHash supports list of options. ([@stoivo][]) | |||
|
|||
* Respect DisabledByDefault for custom cops. ([@XrXr][]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go in the master
section of the changelog, under Bug fixes
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
a5adebd
to
84d7b5b
Compare
Before this commit, DisabledByDefault has no effect on custom cops and they are enabled when the config files contain no mention of them. This is a problematic behavior as CI servers might load multiple custom cop and run Rubocop over repos with vastly different configs. Custom cops end up enabled for repos that don't care about them, simply because they are loaded.
84d7b5b
to
7b145eb
Compare
Thanks! |
Before this commit, DisabledByDefault has no effect on
custom cops and they are enabled when the config files
contain no mention of them. This is a problematic
behavior as CI servers might load multiple custom cop
and run Rubocop over multiple repos. Custom cops end
up enabled for repos that don't care about them, even
though DisabledByDefault is set to true.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.
bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.