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
Rubocop incorrectly tries to transform one line conditional to ternary operator #7705
Comments
I am actually somewhat interested in fixing this myself now. But I need a bit of guidance. I have two questions: I think the right solution here is to transform it to a multiline conditional if there's an elsif clause. I.e.
becomes
Do you agree? If not, I guess the solution would be to not autocorrect this and let the user figure out how to refactor. How would something like that be implemented? Can the autocorrect function just do nothing in some cases or does that cause problems? |
One line conditionals with elsif branches are now transformed into multiline versions. Before this change, they were broken and autocorrect produced code that resulted in a syntax error. See Issue rubocop#7705 for more details.
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! |
…lsif/then/else and add AlwaysCorrectToMultiline config option
…en/else and add AlwaysCorrectToMultiline config option
Rubocop tries to correct a one line conditional with elsif clauses to a ternary operator, but the way it does it is broken and leads to a syntax error.
Expected behavior
The actual expected behavior is a bit of a product decision that I don't dare to make. It could either leave this line unchanged or transform it to multiple ternary operators.
Actual behavior
Rubocop messes up lines with a one line conditional that contains an elsif clause and the result has a syntax error.
Steps to reproduce the problem
Create a file with the following silly bit of code in an otherwise empty directory:
Double check that it works by running it and seeing that you can enter an integer and it produces some output.
Run
rubocop -a
which will try to correct the one line conditional.See that the line with the one line conditional is now messed up. Running the file produces a syntax error.
RuboCop version
0.79.0 (using Parser 2.7.0.2, running on ruby 2.5.1 x86_64-linux-gnu)
The text was updated successfully, but these errors were encountered: