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

Conversation

XrXr
Copy link
Contributor

@XrXr XrXr commented May 1, 2019

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:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@@ -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']
Copy link
Collaborator

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'].

Copy link
Contributor Author

@XrXr XrXr May 13, 2019

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

@bbatsov
Copy link
Collaborator

bbatsov commented May 13, 2019

The changes look good, but your branch has to be rebased on top of the current master branch due to merge conflicts.

@XrXr XrXr force-pushed the custom-cop-disabled-by-default branch 3 times, most recently from 5e833cb to 54b25c7 Compare May 13, 2019 16:56
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][])
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@XrXr XrXr force-pushed the custom-cop-disabled-by-default branch 2 times, most recently from a5adebd to 84d7b5b Compare May 14, 2019 14:30
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.
@XrXr XrXr force-pushed the custom-cop-disabled-by-default branch from 84d7b5b to 7b145eb Compare May 14, 2019 14:30
@bbatsov bbatsov merged commit 98ad15f into rubocop:master May 15, 2019
@bbatsov
Copy link
Collaborator

bbatsov commented May 15, 2019

Thanks!

@XrXr XrXr deleted the custom-cop-disabled-by-default branch May 15, 2019 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants