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

Wrong autocorrection on Rails/EagerEvaluationLogMessage #782

Closed
r7kamura opened this issue Sep 20, 2022 · 1 comment · Fixed by #784
Closed

Wrong autocorrection on Rails/EagerEvaluationLogMessage #782

r7kamura opened this issue Sep 20, 2022 · 1 comment · Fixed by #784
Labels
bug Something isn't working

Comments

@r7kamura
Copy link
Contributor

r7kamura commented Sep 20, 2022

If I try to autocorrect the following code with both Rails/EagerEvaluationLogMessage and Style/MethodCallWithArgsParentheses enabled, it seems to be converted to the wrong code.

Rails.logger.debug "foo#{bar}"

Maybe this is because the 2 correctors are created simultaneously and applied at once.

I don't know how to work around this. Could it be possible to declare information at cop class side that its corrector should be calculated after other autocorrection has been applied?

Expected behavior

Rails.logger.debug { "foo#{bar}" }

Actual behavior

Rails.logger.debug({ "foo#{bar}" })

Steps to reproduce the problem

First, prepare the following set of files...

# .rubocop.yml
require:
  - rubocop-rails

AllCops:
  NewCops: enable

Rails/EagerEvaluationLogMessage:
  Enabled: true

Style/MethodCallWithArgsParentheses:
  Enabled: true
# Gemfile
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'rubocop'
gem 'rubocop-rails'
# example.rb
# frozen_string_literal: true

Rails.logger.debug "foo#{bar}"

and then run the following command:

bundle exec rubocop -a example.rb

RuboCop version

I confirmed this behavior in the following environment:

$ bundle exec rubocop -V
1.36.0 (using Parser 3.1.2.1, rubocop-ast 1.21.0, running on ruby 2.7.4) [x86_64-linux]
  - rubocop-rails 2.16.1
@koic koic added the bug Something isn't working label Sep 20, 2022
koic added a commit to koic/rubocop-rails that referenced this issue Sep 20, 2022
…tionLogMessage`

Fixes rubocop#782.

This PR fixes an incorrect autocorrect for `Rails/EagerEvaluationLogMessage`
when using `Style/MethodCallWithArgsParentheses`'s autocorrection together.
koic added a commit to koic/rubocop-rails that referenced this issue Sep 20, 2022
…tionLogMessage`

Fixes rubocop#782.

This PR fixes an incorrect autocorrect for `Rails/EagerEvaluationLogMessage`
when using `Style/MethodCallWithArgsParentheses`'s autocorrection together.
@koic koic closed this as completed in #784 Sep 22, 2022
koic added a commit that referenced this issue Sep 22, 2022
…ils_eager_evaluation_log_message

[Fix #782] Fix an incorrect autocorrect for `Rails/EagerEvaluationLogMessage`
@r7kamura
Copy link
Contributor Author

Thanks koic! I didn't know this kind of workaround.

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
Development

Successfully merging a pull request may close this issue.

2 participants