Versions

no-nested-ternary

Disallow nested ternary expressions

❄️ Frozen

This rule is currently frozen and is not accepting feature requests.

Nesting ternary expressions can make code more difficult to understand.

const foo = bar ? baz : qux === quxx ? bing : bam;

Rule Details

The no-nested-ternary rule disallows nested ternary expressions.

Examples of incorrect code for this rule:

Open in Playground
/*eslint no-nested-ternary: "error"*/
const thing = foo ? bar : baz === qux ? quxx : foobar;
foo ? baz === qux ? quxx() : foobar() : bar();

Examples of correct code for this rule:

Open in Playground
/*eslint no-nested-ternary: "error"*/
const thing = foo ? bar : foobar;
let otherThing;
if (foo) {
 otherThing = bar;
} else if (baz === qux) {
 otherThing = quxx;
} else {
 otherThing = foobar;
}

Version

This rule was introduced in ESLint v0.2.0.

Resources

Edit this page
© OpenJS Foundation and ESLint contributors, www.openjsf.org. Content licensed under MIT License.
Change Language

AltStyle によって変換されたページ (->オリジナル) /