Eslint参考手册
规则 | Rules
no-nested-ternary
嵌套三元表达式会使代码更难理解。
var foo = bar ? baz : qux === quxx ? bing : bam;
规则细节
no-nested-ternary
规则不允许嵌套的三元表达式。
规则的错误代码示例:
/*eslint no-nested-ternary: "error"*/
var thing = foo ? bar : baz === qux ? quxx : foobar;
foo ? baz === qux ? quxx() : foobar() : bar();
规则的正确代码示例:
/*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;
}
相关规则
- no-ternary
- no-unneeded-ternary
版本
规则在 ESLint 0.2.0中引入。
资源
- Rule source
- Documentation source
规则 | Rules相关

ESLint 是一个代码规范和错误检查工具,有以下几个特性。所有东西都是可以插拔的。你可以调用任意的 rule api 或者 formatter api 去打包或者定义 rule or formatter。任意的 rule 都是独立的。没有特定的 coding style,你可以自己配置。
主页 | https://eslint.org/ |
源码 | https://github.com/eslint/eslint |
发布版本 | 4.12.0 |