no-nested-ternary

禁止嵌套的三元表达式

❄️ Frozen

此规则目前已 冻结,不接受功能请求。

嵌套三元表达式会使代码更难理解。

¥Nesting ternary expressions can make code more difficult to understand.

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

规则详情

¥Rule Details

no-nested-ternary 规则不允许嵌套三元表达式。

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

此规则的错误代码示例:

¥Examples of incorrect code for this rule:

在线运行
/*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:

在线运行
/*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;
}

版本

此规则是在 ESLint v0.2.0 中引入。

资源