Nesting ternary expressions can make code more difficult to understand.
var foo = bar ? baz : qux === quxx ? bing : bam;
The no-nested-ternary
rule disallows nested ternary expressions.
Examples of incorrect code for this rule:
/*eslint no-nested-ternary: "error"*/
var thing = foo ? bar : baz === qux ? quxx : foobar;
foo ? baz === qux ? quxx() : foobar() : bar();
Examples of correct code for this rule:
/*eslint no-nested-ternary: "error"*/
var thing = foo ? bar : foobar;
var thing;
if (foo) {
thing = bar;
} else if (baz === qux) {
thing = quxx;
} else {
thing = foobar;
}
This rule was introduced in ESLint 0.2.0.
© JS Foundation and other contributors
Licensed under the MIT License.
https://eslint.org/docs/rules/no-nested-ternary