Skip to content
You are currently reading docs for v1.x. Go to the latest docs if you are using newer version.

useShorthandAssign

Diagnostic Category: lint/style/useShorthandAssign

Since: v1.3.0

Sources:

Require assignment operator shorthand where possible.

JavaScript provides shorthand operators combining a variable assignment and simple mathematical operation.

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 │

a += 1;
a -= 1;
a *= 1;
biome.json
{
"linter": {
"rules": {
"style": {
"useShorthandAssign": "error"
}
}
}
}