No Destructuring
Disallow destructuring patterns to encourage descriptive parameter names and explicit property access.
Summary
The no-destructuring rule reports destructuring patterns in five contexts:
- Callback parameters.
for...ofloops.- Standalone function parameters.
- Variable declarations.
- Assignment expressions.
Each check can be independently toggled.
Why Use This Rule?
- Encourages descriptive parameter names that convey the whole object's role.
- Makes property access explicit so readers can trace where each value comes from.
- Keeps callback bodies readable with named intermediate constants.
Examples
Configuration
Options
warning
ignoreFiles is an escape hatch for files where this rule genuinely does not apply. It is not intended for routine use.
| Option | Type | Default | Description |
|---|---|---|---|
assignmentExpressions | boolean | true | Ban destructuring in assignment expressions. |
callbackParams | boolean | true | Ban destructuring in callback parameters of these array methods only: map, filter, find, forEach, some, every, reduce, flatMap, sort, findIndex, findLast, findLastIndex. Callbacks to other methods are not covered by this check. |
forOfLoops | boolean | true | Ban destructuring in for...of loops. |
functionParams | boolean | true | Ban destructuring in standalone function/method parameters. |
ignoreFiles | string[] | [] | File names to skip. Supports a leading-* suffix (*.test.ts), an exact path, or a trailing path segment; ** globs are not supported. |
variableDeclarations | boolean | true | Ban destructuring in const/let/var declarations. |
Autofix
Autofix is not available for this rule. Flagged code must be updated manually.
Troubleshooting
- Warning fires on
Object.entries()destructuring — TheforOfLoopscheck applies to allfor...ofdestructuring. Access entries by index instead, or setforOfLoops: false. - Want to allow destructuring in variable declarations only — Set
variableDeclarations: falsewhile keeping the other checks enabled. - Destructuring in a callback to a non-array-method (e.g.
.then(),.addEventListener(), a custom function) is not flagged —callbackParamsonly covers a fixed list of array methods, andfunctionParamsdeliberately skips any function passed as a call argument. There is currently no option that flags these.