no-nested-ternary
禁用嵌套的三元表达式
❄️ Frozen
此规则目前处于冻结状态,不接受功能请求。
嵌套三元表达式会使代码更难理解。
const foo = bar ? baz : qux === quxx ? bing : bam;
规则详情
no-nested-ternary
规则禁用嵌套的三元表达式。
此规则的错误代码示例
在 Playground 中打开
/*eslint no-nested-ternary: "error"*/
const thing = ;
;
此规则的正确代码示例
在 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 中引入。