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/NestedTernaryOperator auto-correction produces invalid code #8821

Closed
Desentso opened this issue Sep 30, 2020 · 0 comments · Fixed by #8832
Closed

Style/NestedTernaryOperator auto-correction produces invalid code #8821

Desentso opened this issue Sep 30, 2020 · 0 comments · Fixed by #8832
Labels

Comments

@Desentso
Copy link

Desentso commented Sep 30, 2020

Style/NestedTernaryOperator auto-correction produces syntactically invalid code. It seems to occur when the nested ternary is enclosed within parentheses. Though it could be argued that in the example outlined later, the "nested ternary" isn't really even a nested ternary but a completely separate statement.


Expected behavior

I would expect it to produce valid code or not try to auto-correct at all.

Actual behavior

Style/NestedTernaryOperator auto-correction produces syntactically invalid code.

Steps to reproduce the problem

Run it on any file that contains structure similar to:

x ? y + (z ? 1 : 0) : nil

You can then see that it produces =>

if x
  y + (z ? 1 : 0
else
  nil
end

which is obviously syntactically invalid, since it's missing the closing parenthesis ).

RuboCop version

0.92.0 (using Parser 2.7.1.5, rubocop-ast 0.7.1, running on ruby 2.5.7 x86_64-darwin18)
@koic koic added the bug label Sep 30, 2020
koic added a commit to koic/rubocop that referenced this issue Oct 2, 2020
…aryOperator`

Fixes rubocop#8821

This PR fixes an incorrect autocorrect for `Style/NestedTernaryOperator` when
using a nested ternary operator expression with no parentheses on the outside.
bbatsov added a commit that referenced this issue Oct 8, 2020
…ator` (#8832)

Fixes #8821

This PR fixes an incorrect autocorrect for `Style/NestedTernaryOperator` when
using a nested ternary operator expression with no parentheses on the outside.

Co-authored-by: Bozhidar Batsov <bozhidar@batsov.com>
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