🚫 This rule is disabled in the ✅ recommended
config.
🔧💡 This rule is automatically fixable by the --fix
CLI option and manually fixable by editor suggestions.
Enforces the use of already destructured objects and their variables over accessing each property individually. Previous destructurings are easily missed which leads to an inconsistent code style.
This rule is partly fixable. It does not fix nested destructuring.
const {a} = foo;
console.log(a, foo.b);
const {a} = foo;
console.log(foo.a);
const {
a: {
b
}
} = foo;
console.log(foo.a.c);
const {bar} = foo;
const {a} = foo.bar;
const {a} = foo;
console.log(a);
console.log(foo.a, foo.b);
const {a} = foo;
console.log(a, foo.b());
const {a} = foo.bar;
console.log(foo.bar);