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

Closed
akwodkiewicz opened this issue Mar 17, 2021 · 1 comment · Fixed by #14226
Closed
Assignees
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 repro:yes rule Relates to ESLint's core rules
Projects

Comments

@akwodkiewicz
Copy link
Contributor

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?
no-mixed-operators

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?
No

@akwodkiewicz akwodkiewicz added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules triage An ESLint team member will look at this issue soon labels Mar 17, 2021
@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
@mdjermanovic mdjermanovic added bug ESLint is working incorrectly repro:yes and removed enhancement This change enhances an existing feature of ESLint triage An ESLint team member will look at this issue soon labels Mar 17, 2021
@mdjermanovic
Copy link
Member

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 added the accepted There is consensus among the team that this change meets the criteria for inclusion label Mar 17, 2021
@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
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Sep 21, 2021
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 repro:yes rule Relates to ESLint's core rules
Projects
No open projects
Triage
Complete
Development

Successfully merging a pull request may close this issue.

2 participants