noNestedTernary
Diagnostic Category: lint/nursery/noNestedTernary
Since: v1.9.3
Sources:
- Same as:
no-nested-ternary
Description
Section titled DescriptionDisallow nested ternary expressions.
Nesting ternary expressions can make code more difficult to understand.
Examples
Section titled ExamplesInvalid
Section titled Invalidconst thing = foo ? bar : baz === qux ? quxx : foobar;
code-block.js:1:27 lint/nursery/noNestedTernary ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Do not nest ternary expressions.
> 1 │ const thing = foo ? bar : baz === qux ? quxx : foobar;
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Nesting ternary expressions can make code more difficult to understand.
ℹ Convert nested ternary expression into if-else statements or separate the conditions to make the logic easier to understand.
foo ? baz === qux ? quxx() : foobar() : bar();
code-block.js:1:7 lint/nursery/noNestedTernary ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Do not nest ternary expressions.
> 1 │ foo ? baz === qux ? quxx() : foobar() : bar();
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Nesting ternary expressions can make code more difficult to understand.
ℹ Convert nested ternary expression into if-else statements or separate the conditions to make the logic easier to understand.
Valid
Section titled Validconst thing = foo ? bar : foobar;
let thing;
if (foo) { thing = bar;} else if (baz === qux) { thing = quxx;} else { thing = foobar;}
How to configure
Section titled How to configure{ "linter": { "rules": { "nursery": { "noNestedTernary": "error" } } }}