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/IfUnlessModifier doesn't add parentheses when correcting an if condition inside a method argument list #8497

Closed
dmytro-savochkin opened this issue Aug 9, 2020 · 0 comments

Comments

@dmytro-savochkin
Copy link

@dmytro-savochkin dmytro-savochkin commented Aug 9, 2020

Cop Style/IfUnlessModifier doesn't add parentheses when correcting an if-end condition inside a method argument list leading to a SyntaxError. I'm going to provide a PR.


Steps to reproduce the problem

Suppose we have the test.rb file with the following code:

puts('string', if 2
                 1
               end)

Run rubocop test.rb --only Style/IfUnlessModifier -a.

Expected behavior

puts('string', (1 if 2))
$ irb
2.5.1 :001 > puts('string', (1 if 2))
string
1
 => nil

Actual behavior

puts('string', 1 if 2)
$ irb
2.5.1 :001 > puts('string', 1 if 2)
Traceback (most recent call last):
        1: from /Users/dmytrosavochkin/.rvm/rubies/ruby-2.5.1/bin/irb:11:in `<main>'
SyntaxError ((irb):1: syntax error, unexpected modifier_if, expecting ')')
puts('string', 1 if 2)
                 ^~

RuboCop version

0.89.0 (using Parser 2.7.1.4, rubocop-ast 0.2.0, running on ruby 2.5.1 x86_64-darwin18)

dmytro-savochkin pushed a commit to dmytro-savochkin/rubocop that referenced this issue Aug 9, 2020
bbatsov added a commit that referenced this issue Aug 10, 2020
…method argument list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

1 participant
You can’t perform that action at this time.