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

Bad autocorrect with Style/IfWithBooleanLiteralBranches #9454

Closed
mvz opened this issue Jan 29, 2021 · 2 comments · Fixed by #9464
Closed

Bad autocorrect with Style/IfWithBooleanLiteralBranches #9454

mvz opened this issue Jan 29, 2021 · 2 comments · Fixed by #9464
Labels

Comments

@mvz
Copy link
Contributor

mvz commented Jan 29, 2021

The new Style/IfWithBooleanLiteralBranches cop does a bad autocorrect in certain cases:

The following code registers the offense and is autocorrected incorrectly:

if foo
  bar
  false
elsif baz?(qux)
  true
else
  false
end

Expected behavior

The code is corrected to

if foo
  bar
  false
else
  baz?(qux)
end

Actual behavior

The code is corrected to:

if foo
  bar
  false
  baz?(qux)
end

Steps to reproduce the problem

  1. Create a .rubocop.yml file containing:
    AllCops:
      NewCops: enable
  2. Paste the code mentioned at the top into a new Ruby file and run rubocop -A or rubocop -a on that file.

RuboCop version

$ [bundle exec] rubocop -V
1.9.0 (using Parser 3.0.0.0, rubocop-ast 1.4.1, running on ruby 3.0.0 x86_64-linux)
@koic koic added the bug label Jan 29, 2021
koic added a commit to koic/rubocop that referenced this issue Jan 29, 2021
…leanLiteralBranches`

Fixes rubocop#9454.

This PR fixes an incorrect auto-correct for `Style/IfWithBooleanLiteralBranches`
when using `elsif do_something?` with boolean literal branches.
bbatsov pushed a commit that referenced this issue Jan 30, 2021
…eralBranches`

Fixes #9454.

This PR fixes an incorrect auto-correct for `Style/IfWithBooleanLiteralBranches`
when using `elsif do_something?` with boolean literal branches.
@mvz
Copy link
Contributor Author

mvz commented Jan 31, 2021

Thanks, @koic!

@koic
Copy link
Member

koic commented Jan 31, 2021

Thank you for the feedback @mvz!

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