版本

no-nested-ternary

禁用嵌套的三元表达式

❄️ Frozen

此规则目前处于冻结状态,不接受功能请求。

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

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

规则详情

no-nested-ternary 规则禁用嵌套的三元表达式。

此规则的错误代码示例

在 Playground 中打开
/*eslint no-nested-ternary: "error"*/

const thing = foo ? bar : baz === qux ? quxx : foobar;

foo ? baz === qux ? quxx() : foobar() : bar();

此规则的正确代码示例

在 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;
}

版本

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

资源

更改语言