noNestedTernary
¥Summary
-
规则生效日期:
v1.9.3¥Rule available since:
v1.9.3 -
诊断类别:
lint/style/noNestedTernary¥Diagnostic Category:
lint/style/noNestedTernary -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 information。
¥The default severity of this rule is information.
-
来源:
¥Sources:
-
与
no-nested-ternary相同¥Same as
no-nested-ternary
-
¥How to configure
{ "linter": { "rules": { "style": { "noNestedTernary": "error" } } }}¥Description
禁止使用嵌套的三元表达式。
¥Disallow nested ternary expressions.
嵌套三元表达式可能会使代码更难理解。
¥Nesting ternary expressions can make code more difficult to understand.
¥Examples
¥Invalid
const thing = foo ? bar : baz === qux ? quxx : foobar;code-block.js:1:27 lint/style/noNestedTernary ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Do not nest ternary expressions.
> 1 │ const thing = foo ? bar : baz === qux ? quxx : foobar;
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Nesting ternary expressions can make code more difficult to understand.
ℹ Convert nested ternary expression into if-else statements or separate the conditions to make the logic easier to understand.
foo ? baz === qux ? quxx() : foobar() : bar();code-block.js:1:7 lint/style/noNestedTernary ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Do not nest ternary expressions.
> 1 │ foo ? baz === qux ? quxx() : foobar() : bar();
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Nesting ternary expressions can make code more difficult to understand.
ℹ Convert nested ternary expression into if-else statements or separate the conditions to make the logic easier to understand.
¥Valid
const thing = foo ? bar : foobar;let thing;
if (foo) { thing = bar;} else if (baz === qux) { thing = quxx;} else { thing = foobar;}¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号