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/RedundantParentheses makes wrong ternary autocorrection #5075

Closed
garettarrowood opened this issue Nov 19, 2017 · 1 comment
Closed
Labels

Comments

@garettarrowood
Copy link
Contributor

garettarrowood commented Nov 19, 2017

While cleaning up a large codebase, I stumbled upon the autocorrection plunder below.


Expected behavior

Style/RedundantParentheses should autocorrect this line of code:

(user.active)? "Y" : "N"

to

user.active ? "Y" : "N"

Actual behavior

However, what actually happens is that the necessary whitespace is not added. And non-executable code is produced in place of the ternary.

-  (user.active)? "Y" : "N"
+  user.active? "Y" : "N"

Attempting to execute the corrected line (where active? is also a defined method):

SyntaxError: unexpected ':', expecting end-of-input

Steps to reproduce the problem

Run rubocop autocorrection on this snippet to produce the results described above.

(user.active)? "Y" : "N"

RuboCop version

0.51.0 (using Parser 2.4.0.0, running on ruby 2.3.3 x86_64-darwin15)
@Drenmi Drenmi added the bug label Nov 23, 2017
@tiagotex
Copy link
Contributor

I'm working on a fix for this bug.

tiagotex added a commit to tiagotex/rubocop that referenced this issue Nov 24, 2017
`Style/RedundantParentheses` tried to autocorrect redundant parentheses in a unspaced ternary operation by removing the parenthesis but wasn't adding an extra space.
bbatsov pushed a commit that referenced this issue Nov 25, 2017
`Style/RedundantParentheses` tried to autocorrect redundant parentheses in a unspaced ternary operation by removing the parenthesis but wasn't adding an extra space.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants