Warn about mixing logical and ternary operators
See original GitHub issueWhat 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 https://github.com/eslint/eslint/issues/7903
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:5 (5 by maintainers)
Top Results From Across the Web
How can I use a ternary operator mixed with logical OR?
So I said to myself instead of using boolean type for trigger variable, let me use int type for the same variable. Such...
Read more >no-mixed-operators - ESLint - Pluggable JavaScript Linter
This rule warns when different operators are used consecutively without parentheses in an expression.
Read more >Nullish coalescing operator (??) - JavaScript - MDN Web Docs
The nullish coalescing (??) operator is a logical operator that returns its right-hand side operand when its left-hand side operand is null ...
Read more >Conditional Operator - an overview | ScienceDirect Topics
is also called a ternary operator because it takes three inputs. ... The tests can be compounded by using logical operators, as follows:....
Read more >Nullish coalescing operator '??' - The Modern JavaScript Tutorial
This is a recent addition to the language. Old browsers may need polyfills. The nullish coalescing operator is written as two question marks...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mysticatea @platinumazure The changes have been made for this and a PR is open for review.
Thanks @mysticatea. In that case, I’m 👍 for this enhancement.