prefer-destructuring
eslint
Safe autofix
eslint.config.js
export default [
{
rules: {
"prefer-destructuring": "error",
},
},
];// With `array` enabled
const foo = array[0];
bar.baz = array[0];
// With `object` enabled
const qux = object.qux;
const quux = object['quux'];const foo = object.bar;// With `array` enabled
const [ foo ] = array;
const arr = array[someIndex];
[bar.baz] = array;
// With `object` enabled
const { baz } = object;
const obj = object.bar;
let bar;
({ bar } = object);const {bar: foo} = object;[bar] = array;Examples from the ESLint documentation.
prefer-destructuring
eslint
export default [
{
rules: {
"prefer-destructuring": "error",
},
},
];prefer-destructuring
eslint plugin · style
{
"rules": {
"prefer-destructuring": "error"
}
}style/useDestructuring
style · since 2.3.9
{
"linter": {
"rules": {
"style": {
"useDestructuring": "error"
}
}
}
}Require destructuring from arrays and/or objects
Disallow else blocks after return statements in if statements
Require or disallow assignment operator shorthand where possible
Require or disallow named function expressions
Disallow use of chained assignment expressions
Disallow if statements as the only statement in else blocks