eslint-plugin-destructure-depth
v1.0.3
Published
This rule enforces the usage of single-level destructuring over deep destructuring.
Downloads
8,879
Readme
eslint-plugin-destructure-depth
This rule enforces the usage of single-level destructuring over deep destructuring.
// bad
// undefined `b` or `object` would cause a runtime error
const {a, b: {d: {e: f}}, c} = object;
// good
const {a, c} = object;
const f = object.?b.?d.?e;
```
Installation
Use Yarn or NPM to install the package.
yarn add eslint-plugin-destructure-depth --dev
Usage
Add destructure-depth
to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:
{
"plugins": ["destructure-depth"]
}
Then configure the rules you want to use under the rules section.
{
"rules": {
"destructure-depth/max-depth": ["warn"]
}
}
To customize the allowed destructuring depth:
{
"rules": {
"destructure-depth/max-depth": [
"warn",
{
"object": {
"max": 1
}
}
]
}
}
This will allow up to 1 level deep of destructuring:
const {
a: { b },
} = object;