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

Style/UnneededCondition auto-correct yields invalid syntax on un-parenthesized multiline statements #6415

Closed
joeadcock opened this issue Oct 27, 2018 · 2 comments
Labels
bug stale Issues that haven't been active in a while

Comments

@joeadcock
Copy link

The Style/UnneededCondition auto-correct can yield syntax errors when a single statement in an else branch spans more than one line without parenthesis.

Example:

def foo(bar = false)
  if bar
    bar
  else
    OpenStruct.new one: 1,
                   two: 2
  end
end

Expected behavior

This should auto-correct to

def foo(bar = false)
  bar || OpenStruct.new(one: 1,
                        two: 2)
end

or

def foo(bar = false)
  bar || OpenStruct.new one: 1, two: 2
end

Actual behavior

Rubocop auto-corrected to (invalid syntax):

def foo(bar = false)
  bar || OpenStruct.new one: 1,
                        two: 2
end

Steps to reproduce the problem

# test.rb
def foo(bar = false)
  bar || OpenStruct.new one: 1,
                        two: 2
end
rubocop --safe-auto-correct test.rb 

RuboCop version

$ rubocop -V
0.60.0 (using Parser 2.5.1.2, running on ruby 2.5.1 x86_64-darwin17)
@bbatsov bbatsov added the bug label Oct 28, 2018
joeadcock added a commit to joeadcock/rubocop that referenced this issue Oct 29, 2018
Fix Style/UnneededCondition auto-correct so that it generates valid
syntax where the else branches contains a multiline statement without
parentheses.
@stale
Copy link

stale bot commented May 8, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

@stale stale bot added the stale Issues that haven't been active in a while label May 8, 2019
@stale
Copy link

stale bot commented Jun 7, 2019

This issues been automatically closed due to lack of activity. Feel free to re-open it if you ever come back to it.

@stale stale bot closed this as completed Jun 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug stale Issues that haven't been active in a while
Projects
None yet
Development

No branches or pull requests

2 participants