Skip to content

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

License

Notifications You must be signed in to change notification settings

isaquediasm/eslint-plugin-destructure-depth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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;

License

MIT License © Isaque Dias

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published