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 autocorrect incorrectly nest conditions #10646

Closed
lacostej opened this issue May 18, 2022 · 0 comments · Fixed by #10647
Closed

Style/SoleNestedConditional autocorrect incorrectly nest conditions #10646

lacostej opened this issue May 18, 2022 · 0 comments · Fixed by #10647
Labels

Comments

@lacostej
Copy link

lacostej commented May 18, 2022

Rubocop proposed to fix this warning

lib/u3d/hub_modules_parser.rb:40:36: C: [Correctable] Style/SoleNestedConditional: Consider merging nested conditions into outer unless conditions.
          download_modules(os: os) unless offline

But broke the code.

Expected behavior

a=false
b=false
c=false
# original code
unless a && b
  puts "HI1" unless c
end
# should have been converted to either
puts "HI3" if !(a && b) && !c
puts "HI4" if !a && !b && !c

Actual behavior

was converted to

puts "HI2" if !a && b && !c

which broke the code

Steps to reproduce the problem

RuboCop version

$ [bundle exec] rubocop -V
1.29.1 (using Parser 3.1.2.0, rubocop-ast 1.18.0, running on ruby 2.7.4 arm64-darwin21)
  - rubocop-rake 0.6.0
@koic koic added the bug label May 18, 2022
koic added a commit to koic/rubocop that referenced this issue May 18, 2022
…dConditional`

Fixes rubocop#10646.

This PR fixes an incorrect autocorrect for `Style/SoleNestedConditional`
when using `unless` and `&&` without parens in the outer condition
and nested modifier condition.
koic added a commit that referenced this issue May 23, 2022
…style_sole_nested_conditional

[Fix #10646] Fix an incorrect autocorrect 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