Examples of correct code for no-unneeded-ternary
See original GitHub issueThis is a discussion/question.
Why are
var a = x ? y : x;
var a = x ? x : 1;
considered correct?
cf http://eslint.org/docs/rules/no-unneeded-ternary#rule-details
You could write them as
var a = x && y;
var a = x || 1;
What am I missing?
This rule disallow ternary operators when simpler alternatives exist.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
No-unneeded-ternary - ESLint - W3cubDocs
This rule disallow ternary operators when simpler alternatives exist. Examples of incorrect code for this rule: /*eslint no-unneeded-ternary: "error"*/var a ...
Read more >ESLint error no-unneeded-ternary - javascript - Stack Overflow
ESLint is telling me this error message inside my JS module: error no-unneeded-ternary Unnecessary use of conditional expression for default ...
Read more >Comparison Operators & Equality · Styleguide JavaScript
Examples. ⇣ Incorrect code for this rule: ... Examples. An array (even an empty one) is an object and Objects will evaluate ......
Read more >ESLint - no-ternary Disallows ternary operators. - Runebook.dev
Examples of incorrect code for this rule: /*eslint no-ternary: "error"*/ var foo = isBar ? baz : qux; function quux() { return foo...
Read more >disallow ternary operators (no-ternary) - Breword 文档集合
The ternary operator is used to conditionally assign a value to a variable. Some believe that the use of ternary operators leads to...
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
I agree, it would be nice if the rule caught these.
Other cases:
I think the rule should still report MemberExpressions, even if it doesn’t autofix them. Getters with side-effects are very rare, so the report would still be useful in the vast majority of cases.
Seems like an oversight to me: should be fixed.