operator-assignment
eslint
Safe autofix
eslint.config.js
export default [
{
rules: {
"operator-assignment": "error",
},
},
];Require or disallow assignment operator shorthand where possible
x = x + y;
x = y * x;
x[0] = x[0] / y;
x.y = x.y << z;x *= y;
x ^= (y + z) / foo();x = y;
x += y;
x = y * z;
x = (x * y) * z;
x[0] /= y;
x[foo()] = x[foo()] % 2;
x = y + x; // `+` is not always commutative (e.g. x = "abc")x = x + y;
x.y = x.y / a.b;Examples from the ESLint documentation.
operator-assignment
eslint
export default [
{
rules: {
"operator-assignment": "error",
},
},
];operator-assignment
eslint plugin · style
{
"rules": {
"operator-assignment": "error"
}
}style/useShorthandAssign
style · since 1.3.0
{
"linter": {
"rules": {
"style": {
"useShorthandAssign": "error"
}
}
}
}Require assignment operator shorthand where possible.
Disallow use of chained assignment expressions
Disallow else blocks after return statements in if statements
Disallow if statements as the only statement in else blocks
Require destructuring from arrays and/or objects