no-nested-ternary - ESLint - Pluggable JavaScript Linter (original) (raw)

Disallow nested ternary expressions

❄️ Frozen

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

Table of Contents

  1. Rule Details
  2. Related Rules
  3. Version
  4. Resources

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