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

Warn about mixing logical and ternary operators #11704

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 enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules

Comments

@mieszko4
Copy link

What rule do you want to change?
no-mixed-operators

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

How will the change be implemented? (New option, new default behavior, etc.)?
new option with default behaviour to warn

Please provide some example code that this change will affect:

// what is priority of this? rule should warn of using brackets explicitly
obj.someValue || conditionSatisfied ? 'good' : 'bad'

// 1 option - rule should not warn
(obj.someValue || conditionSatisfied) ? 'good' : 'bad'

// 2 option - rule should not warn
obj.someValue || (conditionSatisfied ? 'good' : 'bad')

What does the rule currently do for this code?
it does not warn user about mixed logical and ternary expressions

What will the rule do after it's changed?
warn to use brackets around to make it explicit what the priority is

Are you willing to submit a pull request to implement this change?
nope, with this issue, I am just checking if this would make sense
Might be related to #7903

@mieszko4 mieszko4 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 May 10, 2019
@mysticatea mysticatea added evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels May 12, 2019
@mysticatea
Copy link
Member

Thank you for your proposal. I like this idea.

@platinumazure
Copy link
Member

Hi @mieszko4, thanks for the issue.

Is this not currently possible with no-mixed-operators? I'm a little confused.

@mysticatea
Copy link
Member

The current no-mixed-operators checks only binary expressions and logical expressions. This proposal is to add ternary expressions into that.

@platinumazure
Copy link
Member

Thanks @mysticatea. In that case, I'm 👍 for this enhancement.

@mysticatea mysticatea self-assigned this May 22, 2019
@mysticatea mysticatea added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Jun 4, 2019
@karthikkp
Copy link
Contributor

@mysticatea @platinumazure The changes have been made for this and a PR is open for review.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.