๐ Use destructured variables over properties.
๐ซ This rule is disabled in the following configs: โ
recommended, โ๏ธ unopinionated.
๐ก This rule is 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, b} = foo;
console.log(a, b);
// โ
console.log(foo.a, foo.b);// โ
const {a} = foo;
console.log(foo.a);
// โ
const {a} = foo;
console.log(a);// โ
const {
a: {b},
} = foo;
console.log(foo.a.c);// โ
const {bar} = foo;
const {a} = foo.bar;
// โ
const {bar} = foo;
const {a} = bar;// โ
const {a} = foo;
console.log(a, foo.b());// โ
const {a} = foo.bar;
console.log(foo.bar);