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

Style/SoleNestedConditional incorrectly corrects when assignment in conditional #10285

Closed
michaelglass opened this issue Dec 9, 2021 · 2 comments · Fixed by #10287
Closed
Labels

Comments

@michaelglass
Copy link

michaelglass commented Dec 9, 2021

When there's an assignment in a conditional (don't judge me! it's an old codebase!), rubocop -a creates an invalid autocorrection

if a = 4 
  foo(a) if false
end

Expected behavior

either the autocorrector is marked unsafe or the assignment is wrapped in parens, e.g.

if (a = 4) && false
  foo(a)
end

Actual behavior

if a = 4 && false
  foo(a)
end

this autocorrection incorrectly changes the value of a from its original 4 to false

Steps to reproduce the problem

rubocop -a over the example at the top of the file

RuboCop version

1.23.0 (using Parser 3.0.3.2, rubocop-ast 1.14.0, running on ruby 3.0.3 x86_64-darwin21)
@michaelglass
Copy link
Author

also I failed to mention: @koic you are incredible!!

@koic koic added the bug label Dec 9, 2021
@koic
Copy link
Member

koic commented Dec 9, 2021

@michaelglass Thank you for your feedback. I will work on this!

koic added a commit to koic/rubocop that referenced this issue Dec 9, 2021
…dConditional`

Fixes rubocop#10285.

This PR fixes an incorrect autocorrect for `Style/SoleNestedConditional`
when using nested `if` within `if foo = bar`.
bbatsov pushed a commit that referenced this issue Dec 9, 2021
…ional`

Fixes #10285.

This PR fixes an incorrect autocorrect for `Style/SoleNestedConditional`
when using nested `if` within `if foo = bar`.
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