useShorthandAssign
诊断类别:lint/style/useShorthandAssign
¥Diagnostic Category: lint/style/useShorthandAssign
自从:v1.3.0
¥Since: v1.3.0
来源:
¥Sources:
-
与以下相同:
operator-assignment
¥Same as:
operator-assignment
尽可能要求赋值运算符简写。
¥Require assignment operator shorthand where possible.
JavaScript 提供结合变量赋值和简单数学运算的简写运算符。
¥JavaScript provides shorthand operators combining a variable assignment and simple mathematical operation.
¥Examples
¥Invalid
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 │
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 │
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
¥Related links