-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Tweak Lint/UnneededDisable
cop behavior.
#4938
Conversation
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.
The changes look good to me.
end | ||
|
||
it 'does not return an offense' do | ||
puts cop.offenses |
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 looks like it may have been left in by mistake.
I was noticing several weird behaviours with UnneededDisable. First one is linked to #4459, it turns out the following piece of code: ``` # rubocop:disable Lint/UnneededDisable # rubocop:disable all ``` returns the offense "Unnecessary disabling of all cops." where I believe it shouldn't. It seems this was introduced by @rrosenblum changes in `UnneededDisable#check` in d042ccff Second point I noticed and wanted to address is that the following code: ``` # rubocop:disable Lint/UnneededDisable # rubocop:disable Bundler/OrderedGems # rubocop:disable Bundler/OrderedGems ``` produces an offense for unnecessary disabling on line 3. This shouldn't be reported as the cop is disabled. This commit addresses it as well.
This issue reminded me that we should eventually name the cop |
For a backstory see rubocop/rubocop#4459 You can configure rubocop to error out when anyone disables rubocop errors. Which is fine, except the Ruby buildpack needs to do that. We needed a way to disable that check, so this feature was added rubocop/rubocop#4938. This PR is using that feature to hopefully allow anyone to deploy and not get errors from rubocop.
I’m getting this error with rubocop 0.55.0 did this feature ship?
|
@schneems Probably because of this commit released in 0.53.0: a0870fb Changing your statement to EDIT: I just tested the following code against versions of rubocop, and it works with any version >= 0.52.0: # rubocop:disable Lint/UnneededDisable, Lint/UnneededCopDisableDirective
# rubocop:disable all
# any code with or without offenses
# rubocop:enable all
# rubocop:enable Lint/UnneededDisable, Lint/UnneededCopDisableDirective I'm not sure whether this should a core feature of rubocop (being able to ensure no offenses are possible within some code). If so, we should probably add a test that covers this snippet. |
I was noticing several weird behaviours with UnneededDisable.
First one is linked to #4459,
it turns out the following piece of code:
returns the offense "Unnecessary disabling of all cops." where I believe
it shouldn't. It seems this was introduced by @rrosenblum changes
in
UnneededDisable#check
in d042ccffSecond point I noticed and wanted to address is that the following code:
produces an offense for unnecessary disabling on line 3. This shouldn't be
reported as the cop is disabled. This commit addresses it as well.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).rake spec
) are passing.rake internal_investigation
.and description in grammatically correct, complete sentences.
rake generate_cops_documentation
(required only when you've added a new cop or changed the configuration/documentation of an existing cop).