规则名 | 规则类型 | 关联规则 | ||
---|---|---|---|---|
no-nested-ternary |
suggestion |
|
Nesting ternary expressions can make code more difficult to understand.
var foo = bar ? baz : qux === quxx ? bing : bam;
The no-nested-ternary
rule disallows nested ternary expressions.
此规则的 错误 代码实例:
/*eslint no-nested-ternary: "error"*/
var thing = foo ? bar : baz === qux ? quxx : foobar;
foo ? baz === qux ? quxx() : foobar() : bar();
此规则的 正确 代码实例:
::: correct
/*eslint no-nested-ternary: "error"*/
var thing = foo ? bar : foobar;
var thing;
if (foo) {
thing = bar;
} else if (baz === qux) {
thing = quxx;
} else {
thing = foobar;
}