Skip to content

Latest commit

Β 

History

History
67 lines (49 loc) Β· 1.27 KB

no-unreadable-object-destructuring.md

File metadata and controls

67 lines (49 loc) Β· 1.27 KB

no-unreadable-object-destructuring

πŸ“ Disallow unreadable object destructuring.

πŸ’Ό This rule is enabled in the following configs: βœ… recommended, β˜‘οΈ unopinionated.

Destructuring is very useful, but it can also make some code harder to read. This rule prevents hard-to-read object destructuring patterns, including assigning destructured values to object properties.

Examples

// βœ…
const {foo} = object;
// βœ…
const {foo: bar = defaultValue} = object;
// βœ…
const {foo: {bar}} = object;
// ❌
const {[key]: value} = object;

// βœ…
const value = object[key];

A computed key is allowed when the same pattern collects a rest element, since that is the only way to exclude a dynamic property from the rest.

// βœ…
const {[key]: value, ...rest} = object;
// ❌
const {foo: [bar]} = object;

// βœ…
const [bar] = object.foo;
// ❌
const {foo: {bar: {baz}}} = object;

// βœ…
const {baz} = object.foo.bar;
// ❌
({foo: object.property} = object);

// βœ…
({foo} = object);
object.property = foo;