Skip to content

Wrong number of autocorrections #9175

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

Closed
fynsta opened this issue Dec 6, 2020 · 1 comment
Closed

Wrong number of autocorrections #9175

fynsta opened this issue Dec 6, 2020 · 1 comment

Comments

@fynsta
Copy link
Contributor

fynsta commented Dec 6, 2020

When running rubocop -a --only=Layout/LineLength, it displays a total of 12 offenses, of which 7 were autocorrected. In fact, none of those offenses were corrected.

app/models/user.rb:77:151: C: [Corrected] Layout/LineLength: Line is too long. [151/150]
    last_push_token = user_tokens.where.not(push_token: [nil, '']).where.not(updated_at: nil).where.not(last_sign_in: nil).order('updated_at ASC').last

Here, for example, an offense was supposedly corrected, although nothing in this line was changed. And, sure enough, next time I run the same command, the offense shows up again.

I am not sure what is causing the problem as it seems to occur randomly on different line lengths (150-190 characters in my case).


Expected behavior

Either not to show that the offense was corrected, or correct it once and for all.

Steps to reproduce the problem

In rubocop.yml, specify

Layout/LineLength:
  Max: 150

Then run the autocorrection on the line above.

RuboCop version

1.5.2 (using Parser 2.7.2.0, rubocop-ast 1.3.0, running on ruby 2.6.1 x86_64-darwin19)
  - rubocop-faker 1.1.0
  - rubocop-performance 1.9.1
  - rubocop-rails 2.8.1
  - rubocop-rake 0.5.1
  - rubocop-rspec 2.0.1
@dvandersluis
Copy link
Member

This is a continuation of #8978 and #9073. LineLength is a special case for autocorrect because it can only split lines at certain places. Your example should actually autocorrect, but it looks like my fix from #8978 (from before AutoCorrect was enabled by default) is preventing the autocorrect from actually running. I have a fix coming.

dvandersluis added a commit to dvandersluis/rubocop that referenced this issue Dec 8, 2020

Unverified

This user has not yet uploaded their public signing key.
…s not always possible.
marcandre added a commit to marcandre/rubocop that referenced this issue Dec 8, 2020
This addresses a few things:
1) Calling `add_offense` or `add_offense { |corrector| # don't auto-correct }` should be handled the same way. An empty corrector is now replaced by `nil`.
2) Tweaks how the status is handled. Status `:uncorrected` is reserved for cases where there is a corrector but it is not applied.
3) Old style cops' `auto_correct` method is now called even when run without auto-correction. This way we can know if they can auto-correct or not. It also simplifies logic.

I should have done 3) during my refactor (I don't see how it could be incompatible)
@bbatsov bbatsov closed this as completed in 24765a0 Dec 8, 2020
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

No branches or pull requests

2 participants