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

no-mixed-operators: don't require parentheses around a single ternary operator argument #14223

akwodkiewicz opened this issue Mar 17, 2021 · 1 comment


Copy link

@akwodkiewicz akwodkiewicz commented Mar 17, 2021

The only way to write the a ? b && c : d expression in compliance with no-mixed-operators rule (when ternary operator is added to logical operators group) is to use the parentheses twice:

(a) ? (b && c) : d

In my opinion, parentheses around a shouldn't be required.

What rule do you want to change?

Does this change cause the rule to produce more or fewer warnings?
Fewer warnings

How will the change be implemented? (New option, new default behaviour, etc.)?
New default behaviour, I guess

Please provide some example code that this change will affect:

Group: ["&&", "||", "?:"]

a ? (b && c) : d

What does the rule currently do for this code?
Reports an error

What will the rule do after it's changed?
It will not report an error

Are you willing to submit a pull request to implement this change?

@mdjermanovic mdjermanovic added this to Needs Triage in Triage via automation Mar 17, 2021
@mdjermanovic mdjermanovic moved this from Needs Triage to Triaging in Triage Mar 17, 2021
Copy link

@mdjermanovic mdjermanovic commented Mar 17, 2021

Hi @akwodkiewicz, thanks for the issue!

This is a bug, the rule requires additional parentheses around test or the whole ConditionalExpression for no reason.

/* eslint no-mixed-operators: ["error", { groups: [["&&", "||", "?:"]] }] */

a ? b && c : d; // error

a ? (b && c) : d; // error, false positive

(a) ? (b && c) : d; // no error

(a ? (b && c) : d); // no error

Online Demo

Marked as accepted, I'll work on this.


@mdjermanovic mdjermanovic moved this from Triaging to Ready to Implement in Triage Mar 17, 2021
@mdjermanovic mdjermanovic self-assigned this Mar 17, 2021
@nzakas nzakas moved this from Ready to Implement to Pull Request Opened in Triage Mar 20, 2021
Triage automation moved this from Pull Request Opened to Complete Mar 24, 2021
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Sep 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants