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 #9174] Handle send nodes with unparenthesized arguments in Style/SoleNestedConditional #9178

Merged
merged 1 commit into from
Dec 7, 2020

Conversation

dvandersluis
Copy link
Member

If a condition is rewritten by Style/SoleNestedConditional that was an unparenthesized send node, it would be rewritten to a syntax error. This changes it to wrap the send node in parens.

Fixes #9174.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • 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.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@dvandersluis
Copy link
Member Author

FYI - the original correction, if x && y z would be fixed by Style/MethodCallWithArgsParentheses, and this does work if you run rubocop with --only Style/SoleNestedConditional, Style/MethodCallWithArgsParentheses. However, when the set of cops is not limited like this, Lint/Syntax catches it first and MethodCallWithArgsParentheses is unable to correct the code.

It'd be ideal I think if there was a way to immediately queue up a follow up cop after a cop's autocorrection completes (so that logic doesn't have to be duplicated, but I couldn't find a way to do so.

@dvandersluis
Copy link
Member Author

@koic fixed now, thanks!

RUBY

expect_correction(<<~RUBY)
if foo && (ok? bar)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little worrisome is that foo && ok?(bar) is (maybe) more natural code rather than foo && (ok? bar) for user 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree, but I couldn't get it working otherwise. If I try to correct the condition node I get a clobbering error. Any suggestions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I don't have an immediate idea 💦 , but I think it can be improved later. First, I'm going to merge this PR to prevent the syntax error. Thank you for your consideration and fixing!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @koic!

@koic koic merged commit 17a937f into rubocop:master Dec 7, 2020
@dvandersluis dvandersluis deleted the issue/9174 branch January 18, 2021 20:42
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.

False autocorrection when merging "exclude?" in outer conditional
2 participants