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
multiline-ternary doesn't check parentheses #13195
Comments
I think this should be an error as well, right ! (a)
? (b
): c; // <== error |
Yes, if this is a bug the same logic would apply to the check between consequent and alternate.. |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
I personally think this should be classified as a bug, but agree that we should be consistent between rules. |
I'm working on this. |
This change is causing some problems. Here's the first problem from above:
Here's what this rule allows after the MR. The ternary has not really become more readable.:
This should be the only solution:
Fix allowed by the rule change:
This is affecting me because I cannot upgrade my core Eslint version without adding a line to every otherwise readable ternary.
Here's how I must now fix each of those cases:
So why have the multiline parens? Because it handles multiline consequents while keeping alignment. This used to be allowed:
Now I am required to do this:
|
@jsphstls thanks for the suggestion and the detailed examples!
I think this is correct behavior as far as this rule is concerned. This rule doesn't control newlines in parentheses and doesn't control newlines inside the consequent/alternate expressions, so both the second and the third example are valid code for this rule, because We didn't change this behavior, both examples were already valid in the previous version (ESLint v7.1.0).
Same as above. Both fixes should be valid for this particular rule, and they used to be valid before this change.
I hope we'll be able to add autofixing to this rule soon, there's ongoing PR #12982.
This is a matter of preference, of course, but I'd argue that consequent and alternate seem to be more consistently aligned in the fixes than in the original versions: |
Tell us about your environment
What parser (default, Babel-ESLint, etc.) are you using?
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
Online Demo
What did you expect to happen?
It might be expected that parentheses should be treated as a part of the node, so in this case the rule should report that there's a missing newline between test and consequent.
Some rules work that way (e.g.,
array-element-newline
), some don't (function-call-argument-newline
), so I'm not sure if this is a bug.What actually happened? Please include the actual, raw output from ESLint.
no errors
Are you willing to submit a pull request to fix this bug?
yes
The example was with
"always"
, but the same issue exists with"always-multiline"
and"never"
.The text was updated successfully, but these errors were encountered: