# destructuring-assignment-syntax

Rule `sonarjs/destructuring-assignment-syntax`. Destructuring syntax should be used for assignments

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #2130 by reach

## Linters

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

## Code examples

### Incorrect: the rule reports this

```js
function foo (obj1, obj2, array) {
  var a = obj1.a;  // Noncompliant
  var b = obj1.b;

  var name = obj2.name;  // ignored; there's only one extraction-and-assignment

  var zero = array[0];  // Noncompliant
  var one = array[1];
}
```

### Correct: the rule accepts this

```js
function foo (obj1, obj2, array) {
  var {a, b} = obj1;

  var {name} = obj2;  // this syntax works because var name and property name are the same

  var [zero, one] = array;
}
```

Examples from the ESLint documentation.

## Enable it

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

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

## Related rules

- [sonarjs/declarations-in-global-scope](https://lintradar.dev/rules/sonarjs/declarations-in-global-scope.md): Variables and functions should not be declared in the global scope
- [sonarjs/elseif-without-else](https://lintradar.dev/rules/sonarjs/elseif-without-else.md): "if ... else if" constructs should end with "else" clauses
- [sonarjs/cyclomatic-complexity](https://lintradar.dev/rules/sonarjs/cyclomatic-complexity.md): Cyclomatic Complexity of functions should not be too high
- [sonarjs/expression-complexity](https://lintradar.dev/rules/sonarjs/expression-complexity.md): Expressions should not be too complex
- [sonarjs/file-header](https://lintradar.dev/rules/sonarjs/file-header.md): Track lack of copyright and license headers
- [sonarjs/file-name-differ-from-class](https://lintradar.dev/rules/sonarjs/file-name-differ-from-class.md): Default export names and file names should match

---

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