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

rubocop -a cause logic error with Style/SoleNestedConditional cop on version 1.27 + ruby 3.1 #10529

Closed
zw963 opened this issue Apr 12, 2022 · 1 comment · Fixed by #10532
Closed
Labels

Comments

@zw963
Copy link

zw963 commented Apr 12, 2022

Following is a sample.

x = 100
y = true
z = true
foo = true

if x.instance_of? Integer
  if !y && !z
    return puts 'ok' if foo
  end
end

After run rubocop -a or used with solargraph, it will be change to:

x = 100
y = true
z = true
foo = true

return puts 'ok' if x.instance_of? Integer && (!y && !z) && foo

That was not expected, it should be:

x = 100
y = true
z = true
foo = true

return puts 'ok' if (x.instance_of? Integer) && (!y && !z) && foo
@zw963 zw963 changed the title rubocop -a cause syntax error with Style/SoleNestedConditional cop on version 1.27 + ruby 3.1 rubocop -a cause logic error with Style/SoleNestedConditional cop on version 1.27 + ruby 3.1 Apr 12, 2022
@koic koic added the bug label Apr 12, 2022
nobuyo added a commit to nobuyo/rubocop that referenced this issue Apr 12, 2022
nobuyo added a commit to nobuyo/rubocop that referenced this issue Apr 12, 2022
… causes logical error when using a outer condition of send_type by omitting parentheses for method arguments.
nobuyo added a commit to nobuyo/rubocop that referenced this issue Apr 12, 2022
… causes logical error when using a outer condition of send_type by omitting parentheses for method arguments.
nobuyo added a commit to nobuyo/rubocop that referenced this issue Apr 13, 2022
… causes logical error when using a outer condition of method call by omitting parentheses for method arguments.

Update changelog/fix_autocorrect_for_style_sole_nested_confitional.md

Co-authored-by: Koichi ITO <koic.ito@gmail.com>

Update spec/rubocop/cop/style/sole_nested_conditional_spec.rb

Co-authored-by: Koichi ITO <koic.ito@gmail.com>
koic added a commit that referenced this issue Apr 13, 2022
…al-correction

[Fix #10529] Fix autocorrect for `Style/SoleNestedConditional`
@zw963
Copy link
Author

zw963 commented Apr 13, 2022

Thanks you for quick fixs, i consider this is a safe cops, and will cause imperceptible error when run rubocop -a, so if consider release a patch version this or next week?

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