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 #10881] Fix Style/SoleNestedConditional to properly wrap block and csend nodes when necessary #10886

Merged
merged 1 commit into from Aug 9, 2022

Conversation

dvandersluis
Copy link
Member

Style/SoleNestedConditional adds parentheses around send nodes that have unparenthesized arguments, but this wasn't being done for csend or block nodes, so this change fixes that.

Fixes #10881.


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.

RUBY

expect_correction(<<~RUBY)
if foo && (bar&.baz quux)
Copy link
Member

Choose a reason for hiding this comment

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

It would be more better to correct as follows.

Suggested change
if foo && (bar&.baz quux)
if foo && bar&.baz(quux)

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, but this is the existing autocorrection for send nodes I'm just extending it to csend and block nodes as well to prevent syntax errors from autocorrection.

Would you be good with accepting this as-is and improving autocorrection in a future PR?

Copy link
Member

Choose a reason for hiding this comment

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

OK, I think we can do it separately. It would be useful to leave a FIXME comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added!

Comment on lines +699 to +702
if foo && (ok? bar do
do_something
end)
end
Copy link
Member

Choose a reason for hiding this comment

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

Ditto :-)

Suggested change
if foo && (ok? bar do
do_something
end)
end
if foo && ok?(bar) do
do_something
end
end

…p `block` and `csend` nodes when necessary.
@koic koic merged commit 88af469 into rubocop:master Aug 9, 2022
@koic
Copy link
Member

koic commented Aug 9, 2022

Thanks!

@dvandersluis dvandersluis deleted the issue/10881 branch August 9, 2022 03:00
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/SoleNestedConditional] Syntax error when autocorrecting nested if conditions with a block
2 participants