Skip to content

useShorthandAssign (since v1.3.0)

Diagnostic Category: lint/style/useShorthandAssign

Sources:

Require assignment operator shorthand where possible.

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

a = a + 1;
style/useShorthandAssign.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;
style/useShorthandAssign.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;
style/useShorthandAssign.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;