1 # require or disallow assignment operator shorthand where possible (operator-assignment)
3 JavaScript provides shorthand operators that combine variable assignment and some simple mathematical operations. For example, `x = x + 4` can be shortened to `x += 4`. The supported shorthand forms are as follows:
7 -----------|------------
15 x >>>= y | x = x >>> y
23 This rule requires or disallows assignment operator shorthand where possible.
27 This rule has a single string option:
29 * `"always"` (default) requires assignment operator shorthand where possible
30 * `"never"` disallows assignment operator shorthand
34 Examples of **incorrect** code for this rule with the default `"always"` option:
37 /*eslint operator-assignment: ["error", "always"]*/
45 Examples of **correct** code for this rule with the default `"always"` option:
48 /*eslint operator-assignment: ["error", "always"]*/
55 x[foo()] = x[foo()] % 2;
56 x = y + x; // `+` is not always commutative (e.g. x = "abc")
61 Examples of **incorrect** code for this rule with the `"never"` option:
64 /*eslint operator-assignment: ["error", "never"]*/
70 Examples of **correct** code for this rule with the `"never"` option:
73 /*eslint operator-assignment: ["error", "never"]*/
81 Use of operator assignment shorthand is a stylistic choice. Leaving this rule turned off would allow developers to choose which style is more readable on a case-by-case basis.