-
-
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
Add Todo alias and make --disable-autocorrect mark Cops as Todo #7335
Conversation
9f77a2d
to
7198759
Compare
@jonas054 as you added in the disable-uncommentable flag, do you have any feedback on this? |
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 is exactly what I had in mind. Or slightly better than that, actually. I like the [Todo]
output. I just had a couple of comments on the test code.
@@ -3,7 +3,7 @@ | |||
RSpec.describe RuboCop::Cop::Style::DoubleCopDisableDirective do | |||
subject(:cop) { described_class.new } | |||
|
|||
it 'registers an offense when using `#bad_method`' do | |||
it 'registers an offense when using `#bad_method` with disable' do |
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.
It seems I was the one who named this example originally, but now it makes no sense to me. I don't know what #bad_method
or #good_method
means. 🙂 Could you come up with something better?
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.
Addressed :)
@@ -15,6 +15,18 @@ def choose_move(who_to_move) # rubocop:disable Metrics/CyclomaticComplexity | |||
RUBY | |||
end | |||
|
|||
it 'registers an offense when using `#bad_method` with todo' do | |||
expect_offense(<<~RUBY) | |||
def choose_move(who_to_move) # rubocop:todo Metrics/CyclomaticComplexity # rubocop:todo Metrics/AbcSize # rubocop:todo Metrics/MethodLength |
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.
How do we handle mixed rubocop:disable
and rubocop:todo
? Another example?
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.
Based on the current implementation of the cop we're essentially stripping down to just the first cop.
7198759
to
79145bd
Compare
CHANGELOG.md
Outdated
@@ -59,6 +59,7 @@ | |||
* [#7215](https://github.com/rubocop-hq/rubocop/issues/7215): Make it clear what's wrong in the message from `Style/GuardClause`. ([@jonas054][]) | |||
* [#7245](https://github.com/rubocop-hq/rubocop/pull/7245): Make cops detect string interpolations in more contexts: inside of backticks, regular expressions, and symbols. ([@buehmann][]) | |||
* Deprecate the `SafeMode` option. Users will need to upgrade `rubocop-performance` to 1.15.0+ before the `SafeMode` module is removed. ([@rrosenblum][]) | |||
* [#7335](https://github.com/rubocop-hq/rubocop/pull/7335): Add todo as an alias to disable. `--disable-uncorrectable` will not disable Cops using `rubocop:todo` instead of `rubocop:disable`. ([@desheikh][]) |
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.
not -> now
and also Cops -> cops (I see no reason to capitalize it)
I found something in the changelog, so please take a look. Could you also search through all the |
79145bd
to
8fa3f54
Compare
Added additional references to todo where relevant 👍. |
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.
Looks good! 👍
CHANGELOG.md
Outdated
@@ -59,6 +59,7 @@ | |||
* [#7215](https://github.com/rubocop-hq/rubocop/issues/7215): Make it clear what's wrong in the message from `Style/GuardClause`. ([@jonas054][]) | |||
* [#7245](https://github.com/rubocop-hq/rubocop/pull/7245): Make cops detect string interpolations in more contexts: inside of backticks, regular expressions, and symbols. ([@buehmann][]) | |||
* Deprecate the `SafeMode` option. Users will need to upgrade `rubocop-performance` to 1.15.0+ before the `SafeMode` module is removed. ([@rrosenblum][]) | |||
* [#7335](https://github.com/rubocop-hq/rubocop/pull/7335): Add todo as an alias to disable. `--disable-uncorrectable` will now disable cops using `rubocop:todo` instead of `rubocop:disable`. ([@desheikh][]) |
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.
That should be moved to master
.
manual/configuration.md
Outdated
@@ -565,6 +565,14 @@ You can also disable *all* cops with | |||
# rubocop:enable all | |||
``` | |||
|
|||
You can also disable cops using the todo alias. |
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'd mention what this is an alias of exactly and what's the value of having it. Currently this section is a bit confusing.
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 the text
def corrected_with_todo | ||
@status == :corrected_with_todo | ||
end | ||
alias corrected_with_todo? corrected_with_todo |
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 don't get the purpose of this alias.
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.
We want to output [Todo] instead of [Corrected] in the rubocop formatter output.
Having a different corrected state allows us to do that.
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 method above this one, corrected
, is also aliased but I've done some digging in the history and found that there used to be an instance variable called @corrected
with an attr_reader :corrected
and then we needed the alias corrected?
to get the nicely named predicate. Now that we have a @status
instance variable, we could just define corrected?
and corrected_with_todo?
methods and no aliases.
I guess, though, that the new method should have a comment marking it as part of the public API.
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 like that, however perhaps that's more suited to being a separate PR?
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.
OK, I'll merge this one, so you can do a follow-up PR.
This type of reasoning should be in the docs, otherwise no one will figure it out. :-) Overall the code looks good, but I've left some small remarks here and there. |
8fa3f54
to
882eb58
Compare
Thanks! |
🎉 |
We want to to differentiate between disables made intentionally due to false positives, or that we don't plan on fixing vs disables generated using the --disable-uncorrectable flag, which ideally should be reviewed at some point.
#4355 discussed adding a todo directive as part of the disable-uncorrectable however it was never merged.
This is a slightly different approach which adds "todo" as a full alias to "disable" instead and either can be used interchangeably.
The --disable-uncorrectable flag will now generate comments using the todo directive instead of disable.
example:
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.