# operator-assignment

Rule `unicorn/operator-assignment`. Require assignment operator shorthand where possible.

- Source: unicorn
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 9.9M weekly downloads of presets that enable it
- Trend: +28.3% last quarter
- Rank: #1057 by reach, #1312 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/operator-assignment` | no | safe | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/operator-assignment.md) |

## Code examples

### Incorrect: the rule reports this

```js
foo = foo + bar;
```

```js
foo = `${foo} bar`;
```

### Correct: the rule accepts this

```js
foo += bar;
```

```js
foo += ` bar`;
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/operator-assignment": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Unicorn recommended](https://lintradar.dev/presets/unicorn-recommended.md) | ESLint | `eslint-plugin-unicorn` | 340 | 9.5M | +30.3% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [eslint/operator-assignment](https://lintradar.dev/rules/eslint/operator-assignment.md): Require or disallow assignment operator shorthand where possible
- [unicorn/no-useless-else](https://lintradar.dev/rules/unicorn/no-useless-else.md): Disallow `else` after a statement that exits.
- [unicorn/prefer-abort-signal-any](https://lintradar.dev/rules/unicorn/prefer-abort-signal-any.md): Prefer `AbortSignal.any()` over manually forwarding abort events between signals.
- [unicorn/no-unsafe-property-key](https://lintradar.dev/rules/unicorn/no-unsafe-property-key.md): Disallow unsafe values as property keys.
- [unicorn/prefer-abort-signal-timeout](https://lintradar.dev/rules/unicorn/prefer-abort-signal-timeout.md): Prefer `AbortSignal.timeout()` over manually aborting an `AbortController` with `setTimeout()`.
- [unicorn/no-unsafe-json-serialization](https://lintradar.dev/rules/unicorn/no-unsafe-json-serialization.md): Disallow known values that JSON serialization cannot represent faithfully.

---

Web page: https://lintradar.dev/rules/unicorn/operator-assignment. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
