Skip to content

Files

Latest commit

09ae161 · Apr 13, 2024

History

History
 
 

plugin-split-nested-destructuring

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jun 16, 2023
Jun 13, 2023
Jul 20, 2022
Jan 6, 2022
Jun 13, 2023
Apr 10, 2024
Apr 13, 2024
Jun 13, 2023
May 7, 2020
Jun 13, 2023
Apr 8, 2024

@putout/plugin-split-nested-destructuring NPM version

  • Don't use nested destructuring on data that comes from any external data sources (such as REST APIs, GraphQL endpoints or files).
  • Don't use nested destructuring on function arguments that have long or complicated signatures.

(c) Destructuring in JavaScript: the not so good parts

🐊Putout plugin adds ability to split nested destructuring.

Install

npm i @putout/plugin-split-nested-destructuring -D

Rule

{
    "rules": {
        "split-nested-destructuring": "on"
    }
}

❌ Example of incorrect code

const {
    a: {
        b,
    },
    a: {
        b: x,
    },
} = c;

function f({a: {b}}) {
    console.log(b);
}

✅ Example of correct code

const {a} = c;
const {b, b: x} = a;

function f({a}) {
    const {b} = a;
    console.log(b);
}

License

MIT