src/content/docs/linter/rules/use-destructuring.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> :::caution This rule is part of the [nursery](/linter/#nursery) group. This means that it is experimental and the behavior can change at any time. ::: ## Summary - Rule available since: `v2.3.9` - Diagnostic Category: [`lint/nursery/useDestructuring`](/reference/diagnostics#diagnostic-category) - This rule doesn't have a fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`prefer-destructuring`](https://eslint.org/docs/latest/rules/prefer-destructuring){
"linter": {
"rules": {
"nursery": {
"useDestructuring": "error"
}
}
}
}
Require destructuring from arrays and/or objects
With JavaScript ES6, a new syntax was added for creating variables from an array index or object property, called destructuring. This rule enforces usage of destructuring instead of accessing a property through a member expression.
var foo = array[0];
var bar = foo.bar;
var [foo] = array;
var { bar } = foo;
// Variables with type annotations are ignored
const foo: string = object.foo;