Skip to main content

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...of loops, standalone function parameters, variable declarations, and assignment expressions. Each check can be independently toggled. Destructuring in for...of is allowed when the iterable is an Object.entries() call.

Why Use This Rule?

  1. Encourages descriptive parameter names that convey the whole object's role.
  2. Makes property access explicit so readers can trace where each value comes from.
  3. Keeps callback bodies readable with named intermediate constants.

Examples

// Callback — descriptive param, explicit access.
items.map((item) => item.name);

// for...of — Object.entries() destructuring is allowed.
for (const [key, entry] of Object.entries(obj)) {
process(key, entry);
}

// Variable — assign and access separately.
const config = getConfig();
const name = config.name;

Configuration

Enable the rule in your ESLint flat config:

import { noDestructuring } from '@cbnventures/nova/rules/eslint';

export default [
{
plugins: {
'@cbnventures/nova': {
rules: {
'no-destructuring': noDestructuring,
},
},
},
rules: {
'@cbnventures/nova/no-destructuring': ['warn'],
},
},
];

Options

OptionTypeDefaultDescription
functionParamsbooleantrueBan destructuring in standalone function/method parameters.
callbackParamsbooleantrueBan destructuring in callback parameters of array methods.
forOfLoopsbooleantrueBan destructuring in for...of (except Object.entries()).
variableDeclarationsbooleantrueBan destructuring in const/let/var declarations.
assignmentExpressionsbooleantrueBan destructuring in assignment expressions.

Set any option to false to allow destructuring in that specific context.

Troubleshooting

  • Warning fires on Object.entries() destructuring. — The forOfLoops check specifically allows Object.entries(). If the warning still fires, make sure the iterable is a direct Object.entries(x) call.
  • Want to allow destructuring in variable declarations only. — Set variableDeclarations: false while keeping the other checks enabled.