noTernary
¥Summary
-
规则生效日期:
v2.3.8¥Rule available since:
v2.3.8 -
¥Diagnostic Category:
lint/nursery/noTernary -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 information。
¥The default severity of this rule is information.
-
来源:
¥Sources:
-
与
no-ternary相同¥Same as
no-ternary
-
¥How to configure
{ "linter": { "rules": { "nursery": { "noTernary": "error" } } }}¥Description
禁止使用三元运算符。
¥Disallow ternary operators.
三元运算符用于有条件地为变量赋值。有些人认为使用三元运算符会导致代码不清晰。
¥The ternary operator is used to conditionally assign a value to a variable. Some believe that the use of ternary operators leads to unclear code.
¥Examples
¥Invalid
const foo = isBar ? baz : qux;code-block.js:1:13 lint/nursery/noTernary ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Unexpected ternary operator.
> 1 │ const foo = isBar ? baz : qux;
│ ^^^^^^^^^^^^^^^^^
2 │
ℹ Ternary operators can lead to unclear code. Use if-else statement instead.
¥Valid
let foo;
if (isBar) { foo = baz;} else { foo = qux;}¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号