Versions

no-nested-ternary

Disallow nested ternary expressions

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

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

规则细节

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

使用此规则的错误示例:

Open in Playground
/*eslint no-nested-ternary: "error"*/

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

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

使用此规则的正确示例:

Open in Playground
/*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;
}

Version

This rule was introduced in ESLint v0.2.0.

Resources

更改语言