Skip to content

noMisrefactoredShorthandAssign

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.

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
----
a += b
a = a + b
a = a - b
biome.json
{
"linter": {
"rules": {
"suspicious": {
"noMisrefactoredShorthandAssign": "error"
}
}
}
}