eslint-plugin-destructure-depth

This rule enforces the usage of single-level destructuring over deep destructuring.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
eslint-plugin-destructure-depth
1.0.32 years ago4 years agoMinified + gzip package size for eslint-plugin-destructure-depth in KB

Readme

eslint-plugin-destructure-depth
This rule enforces the usage of single-level destructuring over deep destructuring.
````js
// 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;

License

MIT License © Isaque Dias