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

Auto-correction for Style/RedundantParentheses breaks code with yield or super #12124

Closed
ymap opened this issue Aug 16, 2023 · 0 comments · Fixed by #12125
Closed

Auto-correction for Style/RedundantParentheses breaks code with yield or super #12124

ymap opened this issue Aug 16, 2023 · 0 comments · Fixed by #12125
Labels

Comments

@ymap
Copy link
Contributor

ymap commented Aug 16, 2023

The issue occurs when the arguments of yield or super are enclosed in parentheses, and the following conditions are met:

  • There is a newline immediately after the opening parenthesis of the arguments for yield or super
  • There is a space between yield or super and its argument(s)

Here is an example of the code:

yield (
  42
)

Note: The same issue occurs with super when replacing yield with super in the examples above.


Expected behavior

I had expected one of the following three patterns:

  1. Insert a backslash
yield \
  42
  1. Remove the newline
yield 42
  1. Do not auto-correct
yield (
  42
)

Actual behavior

yield
42

Before the correction, 42 was interpreted as an argument to yield. However, after the correction, it interprets yield as having no arguments, and 42 as separate.

Steps to reproduce the problem

  1. Save the following code in a file named example.rb
def foo
  yield (
    42
  )
end
  1. Run bundle exec rubocop -a example.rb

RuboCop version

$ bundle exec rubocop -V
1.56.0 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.0.2) [x86_64-linux]
  - rubocop-performance 1.19.0
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.23.2
@koic koic added the bug label Aug 16, 2023
koic added a commit to koic/rubocop that referenced this issue Aug 16, 2023
Fixes rubocop#12124.

This PR fixes false positives for `Style/RedundantParentheses` when
parentheses in `super` or `yield` call with multiline style argument.
bbatsov pushed a commit that referenced this issue Aug 16, 2023
Fixes #12124.

This PR fixes false positives for `Style/RedundantParentheses` when
parentheses in `super` or `yield` call with multiline style argument.
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