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

[Fix #8299] Fix an incorrect auto-correct for Style/RedundantCondition #8301

Conversation

koic
Copy link
Member

@koic koic commented Jul 10, 2020

Fixes #8299

This PR fixes an incorrect auto-correct for Style/RedundantCondition when using raise without argument parentheses in else.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@marcandre
Copy link
Contributor

This is a good fix, but issues remain for all operators with lower precedence than ||...

if a
  a
else
  b rescue c
# or
  b ? c : d
# or
  b .. c
# or
  b and c
# or
  b if c # or unless / white / until
end

…Condition`

Fixes rubocop#8299

This PR fixes an incorrect auto-correct for `Style/RedundantCondition`
when using `raise`, `rescue`, or `and` without argument parentheses in `else`.
@koic koic force-pushed the fix_incorrect_autocorrect_for_style_redundant_condition branch from 9634803 to d4da633 Compare July 14, 2020 14:33
@koic
Copy link
Member Author

koic commented Jul 14, 2020

Thank you for your review.

This is a good fix, but issues remain for all operators with lower precedence than ||...

Some cases were already covered, but rescue and and were not. I updated this PR to cover them.

Also, the failure of Ruby 2.8.0-dev is probably unrelated to this change. I will investigate (or open an issue) separately from the PR.

@bbatsov bbatsov merged commit 672bac8 into rubocop:master Jul 14, 2020
@bbatsov
Copy link
Collaborator

bbatsov commented Jul 14, 2020

Thanks!

@koic koic deleted the fix_incorrect_autocorrect_for_style_redundant_condition branch July 14, 2020 16:24
@marcandre
Copy link
Contributor

Also, the failure of Ruby 2.8.0-dev is probably unrelated to this change. I will investigate (or open an issue) separately from the PR.

These failures seem to occur reliably. It's quite confusing when we want to merge other things if the build is broken. Could we please fix this (or else temporarily revert) please

@koic
Copy link
Member Author

koic commented Jul 15, 2020

This build error is due to a breaking change in the edge Ruby. RuboCop's master branch is broken independent of this PR.
(I had confirmed it locally so I should have commented it.)

I have asked the following address.
https://bugs.ruby-lang.org/issues/17017#note-6

@marcandre
Copy link
Contributor

Ah, right, sorry.

I even told jeremyevans to watch out for Infinity. I expect it will be fixed quickly 🤞

@koic
Copy link
Member Author

koic commented Jul 15, 2020

Yeah, I got the answer and opened the PR #8343.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Style/RedundantCondition can generate syntax errors when safe-auto-correcting
3 participants