noCommaOperator
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/complexity/noCommaOperator¥Diagnostic Category:
lint/complexity/noCommaOperator -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 warning。
¥The default severity of this rule is warning.
-
来源:
¥Sources:
-
与
no-sequences相同¥Same as
no-sequences
-
¥How to configure
{ "linter": { "rules": { "complexity": { "noCommaOperator": "error" } } }}¥Description
禁止逗号运算符。
¥Disallow comma operator.
逗号运算符包含多个表达式,但只需要一个。它从左到右评估每个操作数并返回最后一个操作数的值。它经常掩盖副作用,它的使用往往是意外。
¥The comma operator includes multiple expressions where only one is expected. It evaluates every operand from left to right and returns the value of the last operand. It frequently obscures side effects, and its use is often an accident.
在 for 的初始化和更新部分中仍然允许使用逗号运算符。
¥The use of the comma operator in the initialization and update parts of a for is still allowed.
¥Examples
¥Invalid
const foo = (doSomething(), 0);code-block.js:1:27 lint/complexity/noCommaOperator ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ The comma operator is disallowed.
> 1 │ const foo = (doSomething(), 0);
│ ^
2 │
ℹ Its use is often confusing and obscures side effects.
for (; doSomething(), !!test; ) {}code-block.js:1:21 lint/complexity/noCommaOperator ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ The comma operator is disallowed.
> 1 │ for (; doSomething(), !!test; ) {}
│ ^
2 │
ℹ Its use is often confusing and obscures side effects.
// Use a semicolon instead.let a, b;a = 1, b = 2;code-block.js:3:6 lint/complexity/noCommaOperator ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ The comma operator is disallowed.
1 │ // Use a semicolon instead.
2 │ let a, b;
> 3 │ a = 1, b = 2;
│ ^
4 │
ℹ Its use is often confusing and obscures side effects.
¥Valid
for(a = 0, b = 0; (a + b) < 10; a++, b += 2) {}¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号