-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[Fix #9175] Don't count autocorrects that will not be performed #9176
Conversation
Good catch. Some methods like |
OTOH, this is not the best fix. I think that In short: it's not the Cop's job to fiddle with |
@marcandre definitely agree (and in fact I called this a "hack" on #9031), but I was working around what is available. I tried playing around with having the corrector lambda return Maybe |
That would be fine too 👍 |
…sses`, `Style/StringLiterals`, `Style/StringLiteralsInInterpolation` to use `Base`. Updated `StringHelp` and `StringLiteralCorrector` for use with `Base` instead of `Cop`.
1b7b1fd
to
80b5607
Compare
Alright this ended up being a bigger change than expected. Rather than overriding However, this also caused some cops to not display the /cc @marcandre @bbatsov |
Layout/LineLength
autocorrection reporting incorrectly80b5607
to
e6dfb41
Compare
Perfect 👍 Before merging, I'd like to understand why it doesn't work for the old style cops, let me check more fully |
@marcandre this is an example of a test that was failing: The The I took a look there are a few others that looked like they might be problematic, so I wanted to flag it. |
…s not always possible.
e6dfb41
to
d2d0166
Compare
Yeah, I agree this is more difficult than it should. Part of it is my fault, I don't think there was a good reason to keep the auto-correct logic so complicated for the old style cops. Another one is that Here's my attempt at fixing all this: #9190. Does it makes sense to you? |
I'm going to close this PR and open a new PR with the converted cops since #9190 supercedes this. |
In #9031, in order to try to stop
Layout/LineLength
from reporting potential corrections that could not be made, I overrodecorrectable?
to only return true if there is a range that can be broken. However, I was not aware thatcorrectable?
is also called before any cops are run to partition cops into autocorrectable and not:https://github.com/rubocop-hq/rubocop/blob/291aec7f04775dbe8aaff0c6a2d7328aaca0427b/lib/rubocop/cop/team.rb#L66-L91
My overridden
correctable?
was therefore causingLayout/LineLength
to not actually autocorrect, ie. #9175.I have changed it now to override
correction_strategy
instead and return:unsupported
if no correction can be made for the code.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 runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.