π 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.
// β
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;