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

Add Todo alias and make --disable-autocorrect mark Cops as Todo #7335

Merged
merged 1 commit into from
Sep 16, 2019

Conversation

desheikh
Copy link
Contributor

@desheikh desheikh commented Sep 8, 2019

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:

# rubocop:todo Metrics/AbcSize
def my_method
...
end
# rubocop:enable Metrics/AbcSize

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.

Sorry, something went wrong.

@desheikh desheikh force-pushed the rubocop-todo-alias branch 6 times, most recently from 9f77a2d to 7198759 Compare September 8, 2019 06:35
@desheikh desheikh marked this pull request as ready for review September 8, 2019 06:35
@desheikh
Copy link
Contributor Author

@jonas054 as you added in the disable-uncommentable flag, do you have any feedback on this?

Copy link
Collaborator

@jonas054 jonas054 left a 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
Copy link
Collaborator

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_methodmeans. 🙂 Could you come up with something better?

Copy link
Contributor Author

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
Copy link
Collaborator

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?

Copy link
Contributor Author

@desheikh desheikh Sep 10, 2019

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.

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][])
Copy link
Collaborator

@jonas054 jonas054 Sep 11, 2019

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)

@jonas054
Copy link
Collaborator

I found something in the changelog, so please take a look. Could you also search through all the .md files under manual for rubocop:disable and see if you find more places where we should mention rubocop:todo? I think there are some, but right now I don't have time to list them here.

@desheikh
Copy link
Contributor Author

Added additional references to todo where relevant 👍.

@desheikh desheikh requested a review from jonas054 September 11, 2019 19:09
Copy link
Collaborator

@jonas054 jonas054 left a 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][])
Copy link
Collaborator

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.

@@ -565,6 +565,14 @@ You can also disable *all* cops with
# rubocop:enable all
```

You can also disable cops using the todo alias.
Copy link
Collaborator

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.

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 the text

def corrected_with_todo
@status == :corrected_with_todo
end
alias corrected_with_todo? corrected_with_todo
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

@jonas054 jonas054 Sep 16, 2019

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.

Copy link
Contributor Author

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?

Copy link
Collaborator

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.

@bbatsov
Copy link
Collaborator

bbatsov commented Sep 15, 2019

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.

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.

@bbatsov bbatsov merged commit 9da708f into rubocop:master Sep 16, 2019
@bbatsov
Copy link
Collaborator

bbatsov commented Sep 16, 2019

Thanks!

@desheikh
Copy link
Contributor Author

🎉

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

3 participants