useShorthandAssign
¥Summary
-
规则生效日期:
v1.3.0¥Rule available since:
v1.3.0 -
诊断类别:
lint/style/useShorthandAssign¥Diagnostic Category:
lint/style/useShorthandAssign -
此规则包含 unsafe 修复程序。
¥This rule has an unsafe fix.
-
此规则的默认严重级别为 information。
¥The default severity of this rule is information.
-
来源:
¥Sources:
-
与
operator-assignment相同¥Same as
operator-assignment
-
¥How to configure
{ "linter": { "rules": { "style": { "useShorthandAssign": "error" } } }}¥Description
尽可能要求赋值运算符简写。
¥Require assignment operator shorthand where possible.
JavaScript 提供结合变量赋值和简单数学运算的简写运算符。
¥JavaScript provides shorthand operators combining a variable assignment and simple mathematical operation.
¥Examples
¥Invalid
a = a + 1;code-block.js:1:1 lint/style/useShorthandAssign FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Assignment (=) can be replaced with operator assignment +=.
> 1 │ a = a + 1;
│ ^^^^^^^^^
2 │
ℹ Unsafe fix: Use += instead.
1 │ - a·=·a·+·1;
1 │ + a·+=·1;
2 2 │
a = a - 1;code-block.js:1:1 lint/style/useShorthandAssign FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Assignment (=) can be replaced with operator assignment -=.
> 1 │ a = a - 1;
│ ^^^^^^^^^
2 │
ℹ Unsafe fix: Use -= instead.
1 │ - a·=·a·-·1;
1 │ + a·-=·1;
2 2 │
a = a * 1;code-block.js:1:1 lint/style/useShorthandAssign FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Assignment (=) can be replaced with operator assignment *=.
> 1 │ a = a * 1;
│ ^^^^^^^^^
2 │
ℹ Unsafe fix: Use *= instead.
1 │ - a·=·a·*·1;
1 │ + a·*=·1;
2 2 │
¥Valid
a += 1;a -= 1;a *= 1;¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号