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

Incorrect auto-correction for Rails/RedundantActiveRecordAllMethod when all has parentheses #1119

Closed
masato-bkn opened this issue Sep 14, 2023 · 0 comments · Fixed by #1120
Closed
Labels
bug Something isn't working

Comments

@masato-bkn
Copy link
Contributor

masato-bkn commented Sep 14, 2023

There is a case where the auto-correction for Rails/RedundantActiveRecordAllMethod failed. I apologize for the recurring oversights.

When all has parentheses and Style/MethodCallWithoutArgsParentheses is disabled, running rubocop results in a failed auto-correction.

User.all().order(:created_at)

Expected behavior

The code should be corrected to:

User.order(:created_at)

Actual behavior

But instead, it gets corrected to:

User.()order(:created_at)

Steps to reproduce the problem

  • Run rubocop with only Rails/RedundantActiveRecordAllMethod enabled:
$ bundle exec rubocop --only Rails/RedundantActiveRecordAllMethod -A ./app/controllers/user_controller.rb
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
Inspecting 1 file
F

Offenses:

app/controllers/user_controller.rb:3:6: C: [Corrected] Rails/RedundantActiveRecordAllMethod: Redundant all detected.
User.all().order(:created_at)
     ^^^
app/controllers/user_controller.rb:3:8: F: Lint/Syntax: unexpected token tIDENTIFIER
(Using Ruby 3.2 parser; configure using TargetRubyVersion parameter, under AllCops)
User.()order(:created_at)
       ^^^^^

1 file inspected, 2 offenses detected, 1 offense corrected


result: User.()order(:created_at)
  • When Style/MethodCallWithoutArgsParentheses is enabled, this issue does not occur.
$ bundle exec rubocop --only Style/MethodCallWithoutArgsParentheses,Rails/RedundantActiveRecordAllMethod -A ./app/controllers/user_controller.rb
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
Inspecting 1 file
C

Offenses:

app/controllers/user_controller.rb:3:6: C: [Corrected] Rails/RedundantActiveRecordAllMethod: Redundant all detected.
User.all().order(:created_at)
     ^^^
app/controllers/user_controller.rb:3:9: C: [Corrected] Style/MethodCallWithoutArgsParentheses: Do not use parentheses for method calls with no arguments.
User.all().order(:created_at)
        ^^

1 file inspected, 2 offenses detected, 2 offenses corrected


result: User.order(:created_at)

RuboCop version

$ bundle exec rubocop -V 
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
1.56.0 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.2.2) [x86_64-darwin22]
  - rubocop-rails 2.21.1
  - rubocop-rspec 2.23.2
masato-bkn added a commit to masato-bkn/rubocop-rails that referenced this issue Sep 14, 2023
…ActiveRecordAllMethod` when `all` has parentheses
masato-bkn added a commit to masato-bkn/rubocop-rails that referenced this issue Sep 14, 2023
…ActiveRecordAllMethod` when `all` has parentheses
masato-bkn added a commit to masato-bkn/rubocop-rails that referenced this issue Sep 14, 2023
…ActiveRecordAllMethod` when `all` has parentheses
@koic koic added the bug Something isn't working label Sep 14, 2023
koic added a commit that referenced this issue Sep 18, 2023
…r_rails_redundant_active_record_all_method_when_all_has_parentheses

[Fix: #1119] Fix an incorrect autocorrect for `Rails/RedundantActiveRecordAllMethod`  when `all` has parentheses
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants