src/content/docs/linter/rules/no-nested-ternary.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.9.3` - Diagnostic Category: [`lint/style/noNestedTernary`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule doesn't have a fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`no-nested-ternary`](https://eslint.org/docs/latest/rules/no-nested-ternary){
"linter": {
"rules": {
"style": {
"noNestedTernary": "error"
}
}
}
}
Disallow nested ternary expressions.
Nesting ternary expressions can make code more difficult to understand.
const thing = foo ? bar : baz === qux ? quxx : foobar;
foo ? baz === qux ? quxx() : foobar() : bar();
const thing = foo ? bar : foobar;
let thing;
if (foo) {
thing = bar;
} else if (baz === qux) {
thing = quxx;
} else {
thing = foobar;
}