版本

no-nested-ternary

不允許巢狀三元運算式

❄️ 已凍結

此規則目前已凍結,且不接受功能請求。

巢狀三元運算式會使程式碼更難以理解。

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

規則詳情

no-nested-ternary 規則不允許巢狀三元運算式。

此規則的錯誤程式碼範例

在遊樂場開啟
/*eslint no-nested-ternary: "error"*/

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

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

此規則的正確程式碼範例

在遊樂場開啟
/*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 中引入。

資源

變更語言