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 for Style/RedundantInterpolation when interpolation is a method call without parentheses #10276

Closed
existentialmutt opened this issue Dec 1, 2021 · 1 comment · Fixed by #10277
Labels

Comments

@existentialmutt
Copy link

The following line is not correctly handled by the autocorrect behavior for Style/RedundantInterpolation

"#{my_method arg}"

Running rubocop -a changes it to

my_method arg.to_s

The correct replacement is

my_method(arg).to_s

Expected behavior

Either the autocorrect behavior for Style/RedundantInterpolation should be updated to handle method calls without parens, or the rule should be marked SafeAutocorrect: false

Actual behavior

Running rubocop -a on a file containing a redundant interpolation can result in an incorrect replacement as shown above.

Steps to reproduce the problem

  1. Save a new file redundant_interpolation_test.rb containing the following:
"#{my_method arg}"
  1. run rubocop -a redundant_interpolation_test.rb

  2. Observe that the file has been changed to

my_method arg.to_s

RuboCop version

bundle exec rubocop -V
1.22.3 (using Parser 3.0.3.1, rubocop-ast 1.13.0, running on ruby 2.6.6 x86_64-linux)
  - rubocop-performance 1.11.5
@koic koic added the bug label Dec 1, 2021
koic added a commit to koic/rubocop that referenced this issue Dec 1, 2021
…Interpolation`

Fixes rubocop#10276.

This PR fixes an incorrect autocorrect for `Style/RedundantInterpolation`
when using a method call without parentheses in string interpolation.
koic added a commit that referenced this issue Dec 1, 2021
…le_redundant_interpolation

[Fix #10276] Fix an incorrect autocorrect for `Style/RedundantInterpolation`
@existentialmutt
Copy link
Author

That was fast! Thanks @koic !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants