Skip to content

Latest commit

 

History

History
50 lines (33 loc) · 770 Bytes

no-nested-ternary.md

File metadata and controls

50 lines (33 loc) · 770 Bytes
规则名 规则类型 关联规则
no-nested-ternary
suggestion
no-ternary
no-unneeded-ternary

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