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 Style/SoleNestedConditional fix #9750

Closed
modosc opened this issue Apr 29, 2021 · 0 comments · Fixed by #9754
Closed

incorrect Style/SoleNestedConditional fix #9750

modosc opened this issue Apr 29, 2021 · 0 comments · Fixed by #9754
Labels

Comments

@modosc
Copy link

modosc commented Apr 29, 2021

Style/SoleNestedConditional generates incorrect ruby when fixing this:

unless foo.to_s == "foo"
  if foo.index("_foo")
    return foo
  end
end

Expected behavior

if foo.to_s != "foo" && foo.index("_foo")
  return foo
end

Actual behavior

if !foo.to_s == "foo" && foo.index("_foo")
  return foo
end

Steps to reproduce the problem

RuboCop version

1.13.0 (using Parser 3.0.1.0, rubocop-ast 1.4.1, running on ruby 2.7.2 x86_64-darwin20)
  - rubocop-performance 1.10.2
  - rubocop-rails 2.9.1
@koic koic added the bug label Apr 30, 2021
koic added a commit to koic/rubocop that referenced this issue Apr 30, 2021
…dConditional`

Fixes rubocop#9750.

This PR fixes an incorrect auto-correct for `Style/SoleNestedConditional`
when when using nested `if` within `unless foo == bar`.

This patch leaves auto-correction from `(!foo == bar)` to `foo != bar` to
`Style/InverseMethods` cop thus simplify its role and implementation.

And this PR adds a cli test to prevent unintended auto-correction when using
`Style/IfUnlessModifier` together for the patch.
@koic koic closed this as completed in #9754 May 2, 2021
koic added a commit that referenced this issue May 2, 2021
…tyle_sole_nested_conditional_cop

[Fix #9750] Fix an incorrect auto-correct for `Style/SoleNestedConditional`
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