# no-nested-assignment

Rule `sonarjs/no-nested-assignment`. Assignments should not be made from within sub-expressions

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1300 by reach, #601 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/no-nested-assignment` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-1121/) |

## Code examples

### Incorrect: the rule reports this

```js
if (val = value() && check()) { // Noncompliant
  // ...
}
```

### Correct: the rule accepts this

```js
val = value();
if (val && check()) {
  // ...
}
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/no-nested-assignment": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/no-mutate-reactive-state-in-updated-hook](https://lintradar.dev/rules/sonarjs/no-mutate-reactive-state-in-updated-hook.md): Reactive state should not be unconditionally mutated inside Vue's "updated" lifecycle hook
- [sonarjs/no-nested-conditional](https://lintradar.dev/rules/sonarjs/no-nested-conditional.md): Ternary operators should not be nested
- [sonarjs/no-misleading-character-class](https://lintradar.dev/rules/sonarjs/no-misleading-character-class.md): Unicode Grapheme Clusters should be avoided inside regex character classes
- [sonarjs/no-nested-functions](https://lintradar.dev/rules/sonarjs/no-nested-functions.md): Functions should not be nested too deeply
- [sonarjs/no-misleading-array-reverse](https://lintradar.dev/rules/sonarjs/no-misleading-array-reverse.md): Array-mutating methods should not be used misleadingly
- [sonarjs/no-os-command-from-path](https://lintradar.dev/rules/sonarjs/no-os-command-from-path.md): OS commands should not rely on PATH resolution

---

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