Skip to content

Commit 66cc1de

Browse files
committed
feature: @putout/plugin-split-call-with-destructuring: add
1 parent 84f3fb9 commit 66cc1de

File tree

16 files changed

+248
-0
lines changed

16 files changed

+248
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,6 +2130,7 @@ It has a lot of plugins divided by groups:
21302130
| Package | Version |
21312131
|--------|-------|
21322132
| [`@putout/plugin-split-assignment-expressions`](/packages/plugin-split-assignment-expressions#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-split-assignment-expressions.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-split-assignment-expressions) |
2133+
| [`@putout/plugin-split-call-with-destructuring`](/packages/plugin-split-call-with-destructuring#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-split-call-with-destructuring.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-split-call-with-destructuring) |
21332134
| [`@putout/plugin-split-variable-declarations`](/packages/plugin-split-variable-declarations#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-split-variable-declarations.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-split-variable-declarations) |
21342135
| [`@putout/plugin-split-nested-destructuring`](/packages/plugin-split-nested-destructuring#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-split-nested-destructuring.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-split-nested-destructuring) |
21352136

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
*.swp
3+
yarn-error.log
4+
5+
coverage
6+
.idea
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {run} from 'madrun';
2+
3+
export default {
4+
'test': () => `tape 'test/*.js'`,
5+
'watch:test': async () => `nodemon -w lib -w test -x ${await run('test')}`,
6+
'lint': () => `putout .`,
7+
'fresh:lint': () => run('lint', '--fresh'),
8+
'lint:fresh': () => run('lint', '--fresh'),
9+
'fix:lint': () => run('lint', '--fix'),
10+
'coverage': async () => `c8 ${await run('test')}`,
11+
'report': () => 'c8 report --reporter=lcov',
12+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.*
2+
test
3+
yarn-error.log
4+
5+
coverage
6+
eslint.config.*
7+
*.config.*
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"check-coverage": true,
3+
"all": true,
4+
"exclude": [
5+
"**/*.spec.*",
6+
"**/fixture",
7+
"test",
8+
".*.*",
9+
"eslint.config.js",
10+
"**/*.config.*"
11+
],
12+
"branches": 100,
13+
"lines": 100,
14+
"functions": 100,
15+
"statements": 100
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"match": {
3+
"*.md": {
4+
"remove-debugger": "off"
5+
},
6+
"*.md*": {
7+
"split-call-with-destructuring": "off"
8+
}
9+
}
10+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) coderaiser
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# @putout/plugin-split-call-with-destructuring [![NPM version][NPMIMGURL]][NPMURL]
2+
3+
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-split-call-with-destructuring.svg?style=flat&longCache=true
4+
[NPMURL]: https://npmjs.org/package/@putout/plugin-split-call-with-destructuring "npm"
5+
6+
🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to split `call` with `destructuring`.
7+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/4da111f11ed1448d7e1707a61439faff/b9a8a2041c6171cd7af5621dce7f902cc8c2ae18).
8+
9+
## Install
10+
11+
```
12+
npm i @putout/plugin-split-call-with-destructuring
13+
```
14+
15+
## Rule
16+
17+
```json
18+
{
19+
"rules": {
20+
"split-call-with-destructuring": "on"
21+
}
22+
}
23+
```
24+
25+
## ❌ Example of incorrect code
26+
27+
```js
28+
console.log('hello')({uid} = path.scope);
29+
console.log('hello')[uid] = path.scope;
30+
```
31+
32+
## ✅ Example of correct code
33+
34+
```js
35+
console.log('hello');
36+
({uid} = path.scope);
37+
38+
console.log('hello');
39+
[uid] = path.scope;
40+
```
41+
42+
## License
43+
44+
MIT
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {safeAlign} from 'eslint-plugin-putout';
2+
3+
export default safeAlign;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
const {types} = require('putout');
4+
const {isIdentifier} = types;
5+
6+
module.exports.report = () => `Split call with destructuring`;
7+
8+
module.exports.replace = () => ({
9+
'__a(__args)({__c} = __d)': `{
10+
__a(__args);
11+
({__c} = __d);
12+
}`,
13+
'__a(__args)[__c] = __d': ({__c}) => {
14+
if (isIdentifier(__c))
15+
return `{
16+
__a(__args);
17+
[__c] = __d;
18+
}`;
19+
20+
__c.elements = __c.expressions;
21+
__c.type = 'ArrayPattern';
22+
delete __c.expressions;
23+
24+
return `{
25+
__a(__args);
26+
__c = __d;
27+
}`;
28+
},
29+
});

0 commit comments

Comments
 (0)