Skip to content

noMisrefactoredShorthandAssign

诊断类别:lint/suspicious/noMisrefactoredShorthandAssign

¥Diagnostic Category: lint/suspicious/noMisrefactoredShorthandAssign

自从:v1.3.0

¥Since: v1.3.0

来源:

¥Sources:

当变量出现在两侧时,禁止简写赋值。

¥Disallow shorthand assign when variable appears on both sides.

此规则有助于避免与重构期间可能发生的错误分配或意外副作用相关的潜在错误。

¥This rule helps to avoid potential bugs related to incorrect assignments or unintended side effects that may occur during refactoring.

¥Examples

¥Invalid

a += a + b
code-block.js:1:1 lint/suspicious/noMisrefactoredShorthandAssign  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━

Variable appears on both sides of an assignment operation.

> 1 │ a += a + b
^^^^^^^^^^
2 │

This assignment might be the result of a wrong refactoring.

Unsafe fix: Use a += b instead.

1 │ a·+=·a·+·b
----
a -= a - b
code-block.js:1:1 lint/suspicious/noMisrefactoredShorthandAssign  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━

Variable appears on both sides of an assignment operation.

> 1 │ a -= a - b
^^^^^^^^^^
2 │

This assignment might be the result of a wrong refactoring.

Unsafe fix: Use a -= b instead.

1 │ a·-=·a·-·b
----
a *= a * b
code-block.js:1:1 lint/suspicious/noMisrefactoredShorthandAssign  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━

Variable appears on both sides of an assignment operation.

> 1 │ a *= a * b
^^^^^^^^^^
2 │

This assignment might be the result of a wrong refactoring.

Unsafe fix: Use a *= b instead.

1 │ a·*=·a·*·b
----

¥Valid

a += b
a = a + b
a = a - b

¥Related links