@putout/plugin-apply-destructuring
Version:
πPutout plugin adds ability use destructuring on variable declarations
101 lines (68 loc) β’ 1.77 kB
Markdown
# @putout/plugin-apply-destructuring [![NPM version][NPMIMGURL]][NPMURL]
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-apply-destructuring.svg?style=flat&longCache=true
[NPMURL]: https://npmjs.org/package/@putout/plugin-apply-destructuring"npm"
> The **destructuring** assignment syntax is a **JavaScript** expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.
>
> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment)
π[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to use **destructuring** on variable declarations.
## Install
```
npm i @putout/plugin-apply-destructuring
```
## Rules
- β
[object](#object);
- β
[array](#array);
- β
[falsy](#falsy);
## Config
Short:
```json
{
"rules": {
"apply-destructuring": "on"
}
}
```
Full:
```json
{
"rules": {
"apply-destructuring/object": "on",
"apply-destructuring/array": "on",
"apply-destructuring/falsy": "on"
}
}
```
## array
## β Example of incorrect code
```js
const first = array[0];
```
## β
Example of correct code
```js
const [first] = array;
```
## object
## β Example of incorrect code
```js
const name = user.name;
hello = world.hello;
```
## β
Example of correct code
```js
const {name} = user;
({hello} = world);
```
## falsy
Check out in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/c9ed04b421d75ae39e58038fa6e14630/4c097e3173990ec7e5ebabbe2cedf8e952092ebf).
## β Example of incorrect code
```js
const {maxElementsInOneLine} = {
options,
};
```
## β
Example of correct code
```js
const {maxElementsInOneLine} = options;
```
## License
MIT