consistent-destructuring

March 27, 2026 ยท View on GitHub

๐Ÿ“ 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.

Examples

// โŒ
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);