Skip to content

Latest commit

 

History

History
59 lines (44 loc) · 1.23 KB

consistent-destructuring.md

File metadata and controls

59 lines (44 loc) · 1.23 KB

Use destructured variables over properties

🚫 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.

Fail

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;

Pass

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);