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
Make pending cops warning slightly more useful #8414
Make pending cops warning slightly more useful #8414
Conversation
…d inform about NewCops: enable
Thank you for opening the PR. However, this proposal has not been accepted in the past. @bbatsov What do you think about that? |
|
||
expect(pending_cops).to include(' - Style/SomeCop (N/A)') | ||
expect(pending_cops).to include("Style/SomeCop: # (new in N/A)\n Enabled: true") |
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.
"new in N/A" sound quite odd, maybe remove it altogether?
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.
Yeah, was thinking the same
Interesting. I wouldn't say it was "not accepted" though. Let's make this warning more easily actionable... I would put the NewCops at the end of the warning, add a URL to the cop when there is one (more so than which version it was added in, since what a cop does is important, when it was added isn't) and call it a day. |
I'm slightly worried that we're going overboard with this message, as it already links to the documentation and that's probably enough. I definitely don't see much point in repeating |
Let's imagine a user that has read (and remembers) the documentation. That user presumably hasn't set
For a user that has not read the documentation, the bit on Otherwise, how do you imagine a user resolving this? googling each cop in turn, then copy-pasting the name, not forgetting the Alternative would be a CLI command that would open the documentation link for each and prompt the user if the cop should be enabled, but seems a bit much. |
Fair enough, you convinced me this might be useful. I like the format you proposed, but we also have to stuff somewhere the version when the cop was introduced (e.g. around the URL). |
Great 😸 So we could keep it where @colszowka is proposing: # https://docs.rubocop.org/rubocop/cops_lint.html#lintduplicatecasecondition
Lint/DuplicateRescueException: # (new in 0.89)
Enabled: true
# https://docs.rubocop.org/rubocop/cops_lint.html#lintmissingsuper
Lint/MissingSuper: # (new in 0.66)
Enabled: true
... |
By the way, I saw that the cop metadata object also has a short description string, maybe it would be better to just put that one instead of the URL? Then no need to even open the link in a browser is neccessary to get what's going on.
Personally from first-hand experience I can say that:
|
Most of the descriptions seem an "english translation" of the cop's name. I say let's go with the URL and the copy-pasteable format and it should be a nice improvement on what we have now |
I'm not big on inline comments in a hash, so I'd rather have this as: # https://docs.rubocop.org/rubocop/cops_lint.html#lintduplicatecasecondition (added in 0.89)
Lint/DuplicateRescueException:
Enabled: true
# or
# https://docs.rubocop.org/rubocop/cops_lint.html#lintduplicatecasecondition
# Added in 0.89
Lint/DuplicateRescueException:
Enabled: true We might also have to add the gem name there if we want to this to be even more informative, although it can easily the inferred from the URL. |
Yeah, they certainly don't add much value. I've been pondering for years whether we should just delete them. |
@colszowka Heads up - I'm planning to cut a new release soon, and it'd be nice if this PR made its way there. |
Sure thing, question is: Where do I get the URL for the cop from? I realized that this is not part of the cop struct or it's metadata passed to the method :/
|
Good point. Looks like you'll have to create a method in |
@marcandre Well if you have some related code snippet handy that might reduce effort on my end indeed :) However, the bigger question I have is: How does this work for plugins / cops extracted to i.e. rubocop-rails? Not sure about the underlying code but I suspect it might be useful to actually change this at the root and always put the url into the metadata object wherever it is generated, what do you think? |
It'd be nice to wrap this up before 1.0. If fetching the URL is problematic I guess you can just rebase, so we can merge this as is and improve it down the road. |
Oops, forgot about this. I'll create a PR adding |
Done in #8579 |
I'll merge this as is and we can add the doc url separately. |
Sorry for the lag, I was on vacation ⛰️ - Thanks for getting this merged! |
Follow up to rubocop#8414. Perhaps the parentheses used in the old plain-text format message remain. In the current YAML format comment it would look redundant. ## Past ```console - Gemspec/DateAssignment (1.10) ``` ## Present ```console Gemspec/DateAssignment: # (new in 1.10) Enabled: true ``` ## Future ```console Gemspec/DateAssignment: # new in 1.10 Enabled: true ```
Follow up to #8414. Perhaps the parentheses used in the old plain-text format message remain. In the current YAML format comment it would look redundant. ## Past ```console - Gemspec/DateAssignment (1.10) ``` ## Present ```console Gemspec/DateAssignment: # (new in 1.10) Enabled: true ``` ## Future ```console Gemspec/DateAssignment: # new in 1.10 Enabled: true ```
As proposed earlier in #8413 this changes the default pending cops warning message to be copy&pasteable.
While writing the specs I also learned about
NewCops: enable
, which probably is what I was originally looking for, so I decied to add that to the warning as well so users are aware of their options.Output now looks like this:
Output before this change:
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.