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

Update: handle parentheses in multiline-ternary (fixes #13195) #13367

Merged
merged 1 commit into from Jun 5, 2020

Conversation

mdjermanovic
Copy link
Member

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[X] Bug fix

fixes #13195

This bug fix can produce more warnings for options "always" and "always-multiline", and fewer warnings for option "never".

What changes did you make? (Give an overview)

The rule will now treat parentheses around test, consequent, and alternate as a part of them.

The following added invalid tests for "always" and "always-multiline" would be valid without this change:

"(a\n) ? b\n: c"
"((a)\n) ? b\n: c"
"a ? (\nb)\n: c"
"a ? (\n(b))\n: c"
"a\n? (b\n): c"
"a\n? ((b)\n): c"
"a\n? b : (\nc)"
"a\n? b : (\n(c))"
"(a\n) ? (\nb\n) : (\nc)"
"((a)\n) ? (\n(b)\n) : (\n(c))"

The following added valid tests for "never would be invalid without this change:

"(a\n) ? b : c"
"((a)\n) ? b : c"
"a ? (\nb) : c"
"a ? (\n(b)) : c"
"a ? (b\n) : c"
"a ? ((b)\n) : c"
"a ? b : (\nc)"
"a ? b : (\n(c))"
"(a\n) ? (\nb\n) : (\nc)"
"((a)\n) ? (\n(b)\n) : (\n(c))"

All other added test cases are regression tests only (they were already valid/invalid).

Also, the reported location will now include parentheses.

Is there anything you'd like reviewers to focus on?

"never" does not actually enforce that the entire ternary expression is on one line. This added test was already valid before this change:

 { code: "a  +\n b ? c +\n d : e + \nf", options: ["never"] }

I'll open a separate issue for this.

@mdjermanovic mdjermanovic added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion labels May 28, 2020
@kaicataldo kaicataldo merged commit 353bfe9 into master Jun 5, 2020
@kaicataldo kaicataldo deleted the issue13195 branch June 5, 2020 23:06
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Dec 3, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Dec 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

multiline-ternary doesn't check parentheses
2 participants