@putout/plugin-putout 12.0.1 β 12.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -28
- package/lib/add-args/index.js +3 -9
- package/lib/apply-async-formatter/index.js +0 -1
- package/lib/apply-create-test/index.js +0 -1
- package/lib/apply-declare/index.js +0 -1
- package/lib/apply-processors-destructuring/index.js +0 -1
- package/lib/apply-remove/index.js +0 -1
- package/lib/check-replace-code/generate-code.js +11 -4
- package/lib/check-replace-code/index.js +12 -8
- package/lib/convert-add-argument-to-add-args/index.js +0 -1
- package/lib/convert-babel-types/index.js +6 -6
- package/lib/convert-dirname-to-url/index.js +0 -1
- package/lib/convert-find-to-traverse/index.js +9 -6
- package/lib/convert-match-to-function/index.js +0 -1
- package/lib/convert-method-to-property/index.js +4 -2
- package/lib/convert-node-to-path-in-get-template-values/index.js +0 -2
- package/lib/convert-number-to-numeric/index.js +0 -1
- package/lib/convert-process-to-find/index.js +0 -1
- package/lib/convert-putout-test-to-create-test/index.js +0 -2
- package/lib/convert-replace-to-function/index.js +0 -1
- package/lib/convert-replace-with/index.js +5 -5
- package/lib/convert-replace-with-multiple/index.js +6 -6
- package/lib/convert-to-no-transform-code/index.js +4 -2
- package/lib/convert-traverse-to-include/index.js +5 -4
- package/lib/convert-traverse-to-replace/index.js +2 -1
- package/lib/convert-url-to-dirname/index.js +0 -1
- package/lib/create-test/index.js +72 -0
- package/lib/declare/index.js +0 -1
- package/lib/declare/operator.js +0 -1
- package/lib/declare/types.json +1 -1
- package/lib/includer/index.js +0 -2
- package/lib/index.js +1 -1
- package/lib/move-require-on-top-level/index.js +8 -3
- package/lib/replace-operate-with-operator/index.js +0 -1
- package/lib/replace-test-message/index.js +10 -4
- package/lib/shorten-imports/index.js +0 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -41,6 +41,7 @@ npm i @putout/plugin-putout -D
|
|
|
41
41
|
"putout/convert-dirname-to-url": "on",
|
|
42
42
|
"putout/convert-url-to-dirname": "on",
|
|
43
43
|
"putout/convert-report-to-function": "on",
|
|
44
|
+
"putout/create-test": "on",
|
|
44
45
|
"putout/shorten-imports": "on",
|
|
45
46
|
"putout/check-replace-code": "on",
|
|
46
47
|
"putout/declare": "on",
|
|
@@ -59,7 +60,6 @@ npm i @putout/plugin-putout -D
|
|
|
59
60
|
test('', async (t) => {
|
|
60
61
|
await t.process({});
|
|
61
62
|
});
|
|
62
|
-
|
|
63
63
|
```
|
|
64
64
|
|
|
65
65
|
### β
Example of correct code
|
|
@@ -87,6 +87,7 @@ export const fix = (path) => {
|
|
|
87
87
|
|
|
88
88
|
```js
|
|
89
89
|
import {operator} from 'putout';
|
|
90
|
+
|
|
90
91
|
const {remove} = operator;
|
|
91
92
|
|
|
92
93
|
export const fix = (path) => {
|
|
@@ -153,11 +154,49 @@ const test = require('@putout/test')({
|
|
|
153
154
|
|
|
154
155
|
```js
|
|
155
156
|
const {createTest} = require('@putout/test');
|
|
157
|
+
|
|
156
158
|
const test = createTest({
|
|
157
159
|
'remove-debugger': plugin,
|
|
158
160
|
});
|
|
159
161
|
```
|
|
160
162
|
|
|
163
|
+
## create-test
|
|
164
|
+
|
|
165
|
+
Add properties to `createTest` options, here is exmample of `.putout.json`:
|
|
166
|
+
|
|
167
|
+
```json
|
|
168
|
+
{
|
|
169
|
+
"rules": {
|
|
170
|
+
"putout/create-test": ["on", {
|
|
171
|
+
"add": [
|
|
172
|
+
["printer", "putout"]
|
|
173
|
+
]
|
|
174
|
+
}]
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Check it out in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e2a9f02d352c064ac9a11688feadc923/2a525f0a8a2794c9d26c23914801c512f347abef).
|
|
180
|
+
|
|
181
|
+
### β Example of incorrect code
|
|
182
|
+
|
|
183
|
+
```js
|
|
184
|
+
createTest(__dirname, {
|
|
185
|
+
'putout/create-test': plugin,
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### β
Example of correct code
|
|
190
|
+
|
|
191
|
+
```js
|
|
192
|
+
createTest(__dirname, {
|
|
193
|
+
printer: 'putout',
|
|
194
|
+
plugins: [
|
|
195
|
+
['putout/create-test', plugin],
|
|
196
|
+
],
|
|
197
|
+
});
|
|
198
|
+
```
|
|
199
|
+
|
|
161
200
|
## convert-number-to-numeric
|
|
162
201
|
|
|
163
202
|
Prevent `Babel` warning: `The node type NumberLiteral has been renamed to NumericLiteral`.
|
|
@@ -250,7 +289,9 @@ module.exports.fix = (path) => {
|
|
|
250
289
|
|
|
251
290
|
```js
|
|
252
291
|
module.exports.fix = (path) => {
|
|
253
|
-
path.replaceWithMultiple([
|
|
292
|
+
path.replaceWithMultiple([
|
|
293
|
+
Identifier('hello'),
|
|
294
|
+
]);
|
|
254
295
|
};
|
|
255
296
|
```
|
|
256
297
|
|
|
@@ -260,7 +301,9 @@ module.exports.fix = (path) => {
|
|
|
260
301
|
const {replaceWithMultiple} = require('putout').operator;
|
|
261
302
|
|
|
262
303
|
module.exports.fix = (path) => {
|
|
263
|
-
replaceWithMultiple(path, [
|
|
304
|
+
replaceWithMultiple(path, [
|
|
305
|
+
Identifier('hello'),
|
|
306
|
+
]);
|
|
264
307
|
};
|
|
265
308
|
```
|
|
266
309
|
|
|
@@ -330,10 +373,8 @@ const {
|
|
|
330
373
|
|
|
331
374
|
```js
|
|
332
375
|
module.exports.replace = () => ({
|
|
333
|
-
'const __a = __b': ({}) => {
|
|
334
|
-
},
|
|
335
|
-
'const __c = __d': ({}, path) => {
|
|
336
|
-
},
|
|
376
|
+
'const __a = __b': ({}) => {},
|
|
377
|
+
'const __c = __d': ({}, path) => {},
|
|
337
378
|
});
|
|
338
379
|
```
|
|
339
380
|
|
|
@@ -341,10 +382,8 @@ module.exports.replace = () => ({
|
|
|
341
382
|
|
|
342
383
|
```js
|
|
343
384
|
module.exports.replace = () => ({
|
|
344
|
-
'const __a = __b': (vars) => {
|
|
345
|
-
},
|
|
346
|
-
'const __c = __d': (vars, path) => {
|
|
347
|
-
},
|
|
385
|
+
'const __a = __b': (vars) => {},
|
|
386
|
+
'const __c = __d': (vars, path) => {},
|
|
348
387
|
});
|
|
349
388
|
```
|
|
350
389
|
|
|
@@ -439,8 +478,7 @@ module.exports.merge = (processedSource, list) => '';
|
|
|
439
478
|
|
|
440
479
|
```js
|
|
441
480
|
module.exports.match = () => ({
|
|
442
|
-
'module.exports.traverse = __a'({}, path) {
|
|
443
|
-
},
|
|
481
|
+
'module.exports.traverse = __a'({}, path) {},
|
|
444
482
|
});
|
|
445
483
|
```
|
|
446
484
|
|
|
@@ -448,8 +486,7 @@ module.exports.match = () => ({
|
|
|
448
486
|
|
|
449
487
|
```js
|
|
450
488
|
module.exports.match = () => ({
|
|
451
|
-
'module.exports.traverse = __a': ({}, path) => {
|
|
452
|
-
},
|
|
489
|
+
'module.exports.traverse = __a': ({}, path) => {},
|
|
453
490
|
});
|
|
454
491
|
```
|
|
455
492
|
|
|
@@ -483,7 +520,10 @@ isIdentifier(a);
|
|
|
483
520
|
### β
Example of correct code
|
|
484
521
|
|
|
485
522
|
```js
|
|
486
|
-
const {
|
|
523
|
+
const {
|
|
524
|
+
operator,
|
|
525
|
+
types,
|
|
526
|
+
} = require('putout');
|
|
487
527
|
const {compare} = operator;
|
|
488
528
|
const {isIdentifier} = types;
|
|
489
529
|
|
|
@@ -563,6 +603,7 @@ module.exports = addArgs({
|
|
|
563
603
|
import {createTest} from '@putout/test';
|
|
564
604
|
import plugin from '@putout/plugin-debugger';
|
|
565
605
|
import {createSimport} from 'simport';
|
|
606
|
+
|
|
566
607
|
const {__dirname} = createSimport(import.meta.url);
|
|
567
608
|
|
|
568
609
|
const test = createTest(__dirname, {
|
|
@@ -640,6 +681,7 @@ test('remove debugger: report', (t) => {
|
|
|
640
681
|
|
|
641
682
|
```js
|
|
642
683
|
const removeDebugger = require('..');
|
|
684
|
+
|
|
643
685
|
const test = require('@putout/test')(__dirname, {
|
|
644
686
|
'remove-debugger': removeDebugger,
|
|
645
687
|
});
|
|
@@ -648,6 +690,7 @@ test('remove debugger: report', (t) => {
|
|
|
648
690
|
const test = require('@putout/test')(__dirname, {
|
|
649
691
|
'remove-debugger': removeDebugger,
|
|
650
692
|
});
|
|
693
|
+
|
|
651
694
|
t.end();
|
|
652
695
|
});
|
|
653
696
|
```
|
|
@@ -659,25 +702,37 @@ test('remove debugger: report', (t) => {
|
|
|
659
702
|
```js
|
|
660
703
|
module.exports.include = () => 'cons __a = __b';
|
|
661
704
|
module.exports.exclude = () => 'var __a = __b';
|
|
662
|
-
|
|
663
705
|
module.exports.include = 'cons __a = __b';
|
|
664
706
|
module.exports.exclude = 'var __a = __b';
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
707
|
+
module.exports.include = [
|
|
708
|
+
'cons __a = __b',
|
|
709
|
+
];
|
|
710
|
+
module.exports.exclude = [
|
|
711
|
+
'var __a = __b',
|
|
712
|
+
];
|
|
668
713
|
```
|
|
669
714
|
|
|
670
715
|
### β
Example of correct code
|
|
671
716
|
|
|
672
717
|
```js
|
|
673
|
-
module.exports.include = () => [
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
module.exports.
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
module.exports.include = () => [
|
|
680
|
-
|
|
718
|
+
module.exports.include = () => [
|
|
719
|
+
'cons __a = __b',
|
|
720
|
+
];
|
|
721
|
+
module.exports.exclude = () => [
|
|
722
|
+
'var __a = __b',
|
|
723
|
+
];
|
|
724
|
+
module.exports.include = () => [
|
|
725
|
+
'cons __a = __b',
|
|
726
|
+
];
|
|
727
|
+
module.exports.exclude = () => [
|
|
728
|
+
'var __a = __b',
|
|
729
|
+
];
|
|
730
|
+
module.exports.include = () => [
|
|
731
|
+
'cons __a = __b',
|
|
732
|
+
];
|
|
733
|
+
module.exports.exclude = () => [
|
|
734
|
+
'var __a = __b',
|
|
735
|
+
];
|
|
681
736
|
```
|
|
682
737
|
|
|
683
738
|
## replace-test-message
|
package/lib/add-args/index.js
CHANGED
|
@@ -8,21 +8,15 @@ module.exports = addArgs({
|
|
|
8
8
|
'test("__a", async (__args) => __body)',
|
|
9
9
|
'test.skip("__a", async (__args) => __body)',
|
|
10
10
|
'test.only("__a", async (__args) => __body)',
|
|
11
|
-
],
|
|
12
|
-
],
|
|
13
|
-
|
|
11
|
+
]],
|
|
14
12
|
process: ['{process}', [
|
|
15
13
|
'test("__a", async (__args) => __body)',
|
|
16
14
|
'test.skip("__a", async (__args) => __body)',
|
|
17
15
|
'test.only("__a", async (__args) => __body)',
|
|
18
|
-
],
|
|
19
|
-
],
|
|
20
|
-
|
|
16
|
+
]],
|
|
21
17
|
noProcess: ['{noProcess}', [
|
|
22
18
|
'test("__a", async (__args) => __body)',
|
|
23
19
|
'test.skip("__a", async (__args) => __body)',
|
|
24
20
|
'test.only("__a", async (__args) => __body)',
|
|
25
|
-
],
|
|
26
|
-
],
|
|
21
|
+
]],
|
|
27
22
|
});
|
|
28
|
-
|
|
@@ -6,7 +6,6 @@ module.exports.replace = () => ({
|
|
|
6
6
|
'async (t) => {await t.process(__args)}': 'async ({process}) => {await process(__args)}',
|
|
7
7
|
'async (t) => {await t.noProcess(__args)}': 'async ({noProcess}) => {await noProcess(__args)}',
|
|
8
8
|
'async (t) => {await t.comparePlaces(__args)}': 'async ({comparePlaces}) => {await comparePlaces(__args)}',
|
|
9
|
-
|
|
10
9
|
'async (t) => {await t.process(__args); t.end();}': 'async ({process}) => {await process(__args)}',
|
|
11
10
|
'async (t) => {await t.noProcess(__args); t.end();}': 'async ({noProcess}) => {await noProcess(__args)}',
|
|
12
11
|
'async (t) => {await t.comparePlaces(__args); t.end();}': 'async ({comparePlaces}) => {await comparePlaces(__args)}',
|
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
const putout = require('putout');
|
|
4
4
|
const tryCatch = require('try-catch');
|
|
5
|
-
|
|
6
5
|
const noop = () => {};
|
|
7
6
|
|
|
8
|
-
const {
|
|
7
|
+
const {
|
|
8
|
+
types,
|
|
9
|
+
operator,
|
|
10
|
+
} = putout;
|
|
11
|
+
|
|
9
12
|
const {replaceWith} = operator;
|
|
13
|
+
|
|
10
14
|
const {
|
|
11
15
|
ArrayPattern,
|
|
12
16
|
ObjectPattern,
|
|
@@ -16,6 +20,7 @@ const {
|
|
|
16
20
|
|
|
17
21
|
module.exports = (rootPath, key) => {
|
|
18
22
|
const getVar = createVarStore(rootPath);
|
|
23
|
+
|
|
19
24
|
const [transformError, result] = tryCatch(putout, key, {
|
|
20
25
|
fix: true,
|
|
21
26
|
isTS: true,
|
|
@@ -75,7 +80,10 @@ module.exports = (rootPath, key) => {
|
|
|
75
80
|
],
|
|
76
81
|
});
|
|
77
82
|
|
|
78
|
-
return [
|
|
83
|
+
return [
|
|
84
|
+
transformError,
|
|
85
|
+
result?.code,
|
|
86
|
+
];
|
|
79
87
|
};
|
|
80
88
|
|
|
81
89
|
function createVarStore(path) {
|
|
@@ -102,4 +110,3 @@ function objectify(path) {
|
|
|
102
110
|
if (isAssign && parentPath.get('right') === path)
|
|
103
111
|
return replaceWith(path, ObjectExpression([]));
|
|
104
112
|
}
|
|
105
|
-
|
|
@@ -2,11 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const putout = require('putout');
|
|
4
4
|
const tryCatch = require('try-catch');
|
|
5
|
-
|
|
6
5
|
const generateCode = require('./generate-code');
|
|
7
|
-
|
|
8
6
|
const noop = () => {};
|
|
9
|
-
|
|
10
7
|
const {operator} = putout;
|
|
11
8
|
const {
|
|
12
9
|
compare,
|
|
@@ -15,7 +12,6 @@ const {
|
|
|
15
12
|
} = operator;
|
|
16
13
|
|
|
17
14
|
const name = '__putout_plugin_check_replace_code';
|
|
18
|
-
|
|
19
15
|
const get = (path) => path[name];
|
|
20
16
|
const set = (path) => path[name] = true;
|
|
21
17
|
|
|
@@ -61,6 +57,7 @@ module.exports.traverse = ({push}) => ({
|
|
|
61
57
|
mainPath: path,
|
|
62
58
|
path: propertyPath,
|
|
63
59
|
});
|
|
60
|
+
|
|
64
61
|
return;
|
|
65
62
|
}
|
|
66
63
|
|
|
@@ -73,6 +70,7 @@ module.exports.traverse = ({push}) => ({
|
|
|
73
70
|
mainPath: path,
|
|
74
71
|
path: propertyPath,
|
|
75
72
|
});
|
|
73
|
+
|
|
76
74
|
return;
|
|
77
75
|
}
|
|
78
76
|
|
|
@@ -95,6 +93,7 @@ module.exports.traverse = ({push}) => ({
|
|
|
95
93
|
mainPath: path,
|
|
96
94
|
path: propertyPath,
|
|
97
95
|
});
|
|
96
|
+
|
|
98
97
|
return;
|
|
99
98
|
}
|
|
100
99
|
|
|
@@ -116,13 +115,19 @@ function parseKey(propertyPath) {
|
|
|
116
115
|
const [isComputed, key] = compute(keyPath);
|
|
117
116
|
|
|
118
117
|
if (!isComputed)
|
|
119
|
-
return [
|
|
118
|
+
return [
|
|
119
|
+
Error(`Replace key cannot be computed: '${keyPath.toString()}'`),
|
|
120
|
+
];
|
|
120
121
|
|
|
121
|
-
return [
|
|
122
|
+
return [
|
|
123
|
+
null,
|
|
124
|
+
key,
|
|
125
|
+
];
|
|
122
126
|
}
|
|
123
127
|
|
|
124
128
|
function hasMatch(path) {
|
|
125
|
-
const {body} = path.scope
|
|
129
|
+
const {body} = path.scope
|
|
130
|
+
.getProgramParent().path.node;
|
|
126
131
|
|
|
127
132
|
for (const current of body) {
|
|
128
133
|
if (compare(current, 'module.exports.match = __a'))
|
|
@@ -131,4 +136,3 @@ function hasMatch(path) {
|
|
|
131
136
|
|
|
132
137
|
return false;
|
|
133
138
|
}
|
|
134
|
-
|
|
@@ -17,16 +17,17 @@ module.exports.report = () => {
|
|
|
17
17
|
|
|
18
18
|
function isRequire(path) {
|
|
19
19
|
return path
|
|
20
|
-
.get('callee')
|
|
21
|
-
|
|
20
|
+
.get('callee').isIdentifier({
|
|
21
|
+
name: 'require',
|
|
22
|
+
});
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
function isBabelTypes(path) {
|
|
25
26
|
return path
|
|
26
|
-
.get('arguments.0')
|
|
27
|
-
|
|
27
|
+
.get('arguments.0').isStringLiteral({
|
|
28
|
+
value: '@babel/types',
|
|
29
|
+
});
|
|
28
30
|
}
|
|
29
|
-
|
|
30
31
|
module.exports.traverse = ({push}) => ({
|
|
31
32
|
CallExpression(path) {
|
|
32
33
|
if (!isRequire(path))
|
|
@@ -42,4 +43,3 @@ module.exports.traverse = ({push}) => ({
|
|
|
42
43
|
module.exports.fix = (path) => {
|
|
43
44
|
replaceWith(path, astRequire);
|
|
44
45
|
};
|
|
45
|
-
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
types,
|
|
5
|
+
operator,
|
|
6
|
+
} = require('putout');
|
|
7
|
+
|
|
4
8
|
const {replaceWith} = operator;
|
|
5
9
|
|
|
6
10
|
const {
|
|
@@ -24,11 +28,9 @@ module.exports.fix = fixType({
|
|
|
24
28
|
isMemberExpression: (path) => {
|
|
25
29
|
path.get('property').node.name = 'traverse';
|
|
26
30
|
},
|
|
27
|
-
|
|
28
31
|
isFunction: (path) => {
|
|
29
32
|
path.node.params = [path.node.params[1]];
|
|
30
33
|
},
|
|
31
|
-
|
|
32
34
|
isCallExpression: (path) => {
|
|
33
35
|
replaceWith(path, ReturnStatement(path.node.arguments[1]));
|
|
34
36
|
},
|
|
@@ -46,7 +48,6 @@ module.exports.traverse = ({push}) => ({
|
|
|
46
48
|
return;
|
|
47
49
|
|
|
48
50
|
const traverseCallPath = getTraverseCall(rightPath);
|
|
49
|
-
|
|
50
51
|
push(traverseCallPath);
|
|
51
52
|
push(leftPath);
|
|
52
53
|
push(rightPath);
|
|
@@ -72,14 +73,16 @@ function getTraverseCall(path) {
|
|
|
72
73
|
|
|
73
74
|
path.traverse({
|
|
74
75
|
CallExpression(path) {
|
|
75
|
-
if (!path.get('callee').isIdentifier({
|
|
76
|
+
if (!path.get('callee').isIdentifier({
|
|
77
|
+
name: 'traverse',
|
|
78
|
+
}))
|
|
76
79
|
return;
|
|
77
80
|
|
|
78
81
|
result = path;
|
|
82
|
+
|
|
79
83
|
path.stop();
|
|
80
84
|
},
|
|
81
85
|
});
|
|
82
86
|
|
|
83
87
|
return result;
|
|
84
88
|
}
|
|
85
|
-
|
|
@@ -10,7 +10,9 @@ const {ObjectProperty} = types;
|
|
|
10
10
|
|
|
11
11
|
module.exports.report = () => 'Object Property should be used instead of Method';
|
|
12
12
|
|
|
13
|
-
module.exports.include = () => [
|
|
13
|
+
module.exports.include = () => [
|
|
14
|
+
'ObjectMethod',
|
|
15
|
+
];
|
|
14
16
|
|
|
15
17
|
module.exports.filter = (path) => {
|
|
16
18
|
if (!path.node.params.length)
|
|
@@ -26,9 +28,9 @@ module.exports.filter = (path) => {
|
|
|
26
28
|
|
|
27
29
|
module.exports.fix = (path) => {
|
|
28
30
|
const keyPath = path.get('key');
|
|
31
|
+
|
|
29
32
|
path.node.type = 'ArrowFunctionExpression';
|
|
30
33
|
path.node.id = null;
|
|
31
34
|
|
|
32
35
|
replaceWith(path, ObjectProperty(keyPath.node, path.node));
|
|
33
36
|
};
|
|
34
|
-
|
|
@@ -35,7 +35,6 @@ module.exports.traverse = ({push}) => ({
|
|
|
35
35
|
'getTemplateValues(__a, __b)': (path) => {
|
|
36
36
|
const {scope} = path;
|
|
37
37
|
const {bindings} = scope;
|
|
38
|
-
|
|
39
38
|
const __aPath = path.get('arguments.0');
|
|
40
39
|
|
|
41
40
|
if (__aPath.isMemberExpression()) {
|
|
@@ -70,4 +69,3 @@ module.exports.traverse = ({push}) => ({
|
|
|
70
69
|
});
|
|
71
70
|
},
|
|
72
71
|
});
|
|
73
|
-
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
const {assign} = Object;
|
|
4
4
|
|
|
5
5
|
module.exports.report = () => `Use 'createTest' instead of 'putoutTest'`;
|
|
6
|
-
|
|
7
6
|
module.exports.filter = ({scope}) => !scope.bindings.createTest;
|
|
8
7
|
|
|
9
8
|
module.exports.include = () => [
|
|
@@ -21,4 +20,3 @@ module.exports.fix = (path) => {
|
|
|
21
20
|
|
|
22
21
|
path.scope.rename('putoutTest', 'createTest');
|
|
23
22
|
};
|
|
24
|
-
|
|
@@ -50,8 +50,7 @@ module.exports.fix = ({path, calleePath, property, object, program, isInserted})
|
|
|
50
50
|
const id = Identifier('replaceWith');
|
|
51
51
|
const varPath = getVarPath(bindings);
|
|
52
52
|
|
|
53
|
-
varPath.node.id.properties
|
|
54
|
-
.unshift(ObjectProperty(id, id, false, true));
|
|
53
|
+
varPath.node.id.properties.unshift(ObjectProperty(id, id, false, true));
|
|
55
54
|
};
|
|
56
55
|
|
|
57
56
|
function getVarPath(bindings) {
|
|
@@ -65,7 +64,6 @@ function getVarPath(bindings) {
|
|
|
65
64
|
|
|
66
65
|
return insertAfter.path;
|
|
67
66
|
}
|
|
68
|
-
|
|
69
67
|
module.exports.traverse = ({push}) => {
|
|
70
68
|
const isInserted = fullstore();
|
|
71
69
|
|
|
@@ -76,7 +74,10 @@ module.exports.traverse = ({push}) => {
|
|
|
76
74
|
if (!calleePath.isMemberExpression())
|
|
77
75
|
return;
|
|
78
76
|
|
|
79
|
-
const {
|
|
77
|
+
const {
|
|
78
|
+
object,
|
|
79
|
+
property,
|
|
80
|
+
} = calleePath.node;
|
|
80
81
|
|
|
81
82
|
if (property.name !== 'replaceWith')
|
|
82
83
|
return;
|
|
@@ -94,4 +95,3 @@ module.exports.traverse = ({push}) => {
|
|
|
94
95
|
},
|
|
95
96
|
};
|
|
96
97
|
};
|
|
97
|
-
|
|
@@ -38,10 +38,9 @@ module.exports.fix = ({path, calleePath, property, object, program}) => {
|
|
|
38
38
|
return insertAfter(strictModePath, replaceWithAST);
|
|
39
39
|
|
|
40
40
|
const id = Identifier('replaceWithMultiple');
|
|
41
|
-
|
|
42
41
|
const varPath = getVarPath(bindings);
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
|
|
43
|
+
varPath.node.id.properties.push(ObjectProperty(id, id, false, true));
|
|
45
44
|
};
|
|
46
45
|
|
|
47
46
|
function getVarPath(bindings) {
|
|
@@ -55,7 +54,6 @@ function getVarPath(bindings) {
|
|
|
55
54
|
|
|
56
55
|
return insertAfter.path;
|
|
57
56
|
}
|
|
58
|
-
|
|
59
57
|
module.exports.traverse = ({push}) => ({
|
|
60
58
|
CallExpression(path) {
|
|
61
59
|
const calleePath = path.get('callee');
|
|
@@ -63,7 +61,10 @@ module.exports.traverse = ({push}) => ({
|
|
|
63
61
|
if (!calleePath.isMemberExpression())
|
|
64
62
|
return;
|
|
65
63
|
|
|
66
|
-
const {
|
|
64
|
+
const {
|
|
65
|
+
object,
|
|
66
|
+
property,
|
|
67
|
+
} = calleePath.node;
|
|
67
68
|
|
|
68
69
|
if (property.name !== 'replaceWithMultiple')
|
|
69
70
|
return;
|
|
@@ -79,4 +80,3 @@ module.exports.traverse = ({push}) => ({
|
|
|
79
80
|
});
|
|
80
81
|
},
|
|
81
82
|
});
|
|
82
|
-
|
|
@@ -16,7 +16,10 @@ module.exports.traverse = ({push}) => ({
|
|
|
16
16
|
if (!calleePath.isMemberExpression())
|
|
17
17
|
return;
|
|
18
18
|
|
|
19
|
-
const {
|
|
19
|
+
const {
|
|
20
|
+
object,
|
|
21
|
+
property,
|
|
22
|
+
} = calleePath.node;
|
|
20
23
|
|
|
21
24
|
if (object.name !== 't' || property.name !== 'transformCode')
|
|
22
25
|
return;
|
|
@@ -40,4 +43,3 @@ module.exports.fix = ({path, calleePath}) => {
|
|
|
40
43
|
calleePath.node.property = Identifier('noTransformCode');
|
|
41
44
|
path.node.arguments.pop();
|
|
42
45
|
};
|
|
43
|
-
|
|
@@ -5,12 +5,14 @@ const {
|
|
|
5
5
|
template,
|
|
6
6
|
operator,
|
|
7
7
|
} = require('putout');
|
|
8
|
+
|
|
8
9
|
const {StringLiteral} = types;
|
|
9
10
|
const {compare} = operator;
|
|
10
11
|
|
|
11
|
-
const isPush = (path) => path
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const isPush = (path) => path
|
|
13
|
+
.get('value').isIdentifier({
|
|
14
|
+
name: 'push',
|
|
15
|
+
});
|
|
14
16
|
|
|
15
17
|
module.exports.report = () => 'Includer should be used instead of Traverser';
|
|
16
18
|
|
|
@@ -69,4 +71,3 @@ function isBlock(path) {
|
|
|
69
71
|
|
|
70
72
|
return compare(node, 'push(path)');
|
|
71
73
|
}
|
|
72
|
-
|
|
@@ -11,6 +11,7 @@ module.exports.report = () => 'Replacer should be used instead of Traverser (htt
|
|
|
11
11
|
module.exports.match = () => ({
|
|
12
12
|
'module.exports.traverse = (__args) => __a': ({__args}, path) => {
|
|
13
13
|
const program = path.scope.getProgramParent().path;
|
|
14
|
+
|
|
14
15
|
const withFix = contains(program, [
|
|
15
16
|
'module.exports.fix = __a',
|
|
16
17
|
]);
|
|
@@ -54,6 +55,7 @@ function check(path) {
|
|
|
54
55
|
return;
|
|
55
56
|
|
|
56
57
|
hasTraverseMethod = true;
|
|
58
|
+
|
|
57
59
|
path.stop();
|
|
58
60
|
},
|
|
59
61
|
'push(__a)': (path) => {
|
|
@@ -64,4 +66,3 @@ function check(path) {
|
|
|
64
66
|
|
|
65
67
|
return hasPushCall || hasTraverseMethod;
|
|
66
68
|
}
|
|
67
|
-
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
operator,
|
|
5
|
+
types,
|
|
6
|
+
} = require('putout');
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
StringLiteral,
|
|
10
|
+
ArrayExpression,
|
|
11
|
+
Identifier,
|
|
12
|
+
ObjectProperty,
|
|
13
|
+
ObjectExpression,
|
|
14
|
+
} = types;
|
|
15
|
+
|
|
16
|
+
const {
|
|
17
|
+
replaceWith,
|
|
18
|
+
getProperty,
|
|
19
|
+
} = operator;
|
|
20
|
+
|
|
21
|
+
const selector = 'createTest(__dirname, __object)';
|
|
22
|
+
|
|
23
|
+
module.exports.report = () => `Apply modifications to 'createTest()' options`;
|
|
24
|
+
|
|
25
|
+
module.exports.include = () => [
|
|
26
|
+
selector,
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
module.exports.fix = (path, {options}) => {
|
|
30
|
+
const objectPath = path.get('arguments.1');
|
|
31
|
+
|
|
32
|
+
if (!getProperty(objectPath, 'plugins'))
|
|
33
|
+
convert(objectPath);
|
|
34
|
+
|
|
35
|
+
for (const [name, value] of options.add) {
|
|
36
|
+
if (getProperty(objectPath, name))
|
|
37
|
+
continue;
|
|
38
|
+
|
|
39
|
+
const property = ObjectProperty(Identifier(name), StringLiteral(value));
|
|
40
|
+
objectPath.node.properties.unshift(property);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
module.exports.filter = (path, {options}) => {
|
|
45
|
+
if (!options.add)
|
|
46
|
+
return false;
|
|
47
|
+
|
|
48
|
+
const objectPath = path.get('arguments.1');
|
|
49
|
+
|
|
50
|
+
for (const [name] of options.add) {
|
|
51
|
+
if (!getProperty(objectPath, name))
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return false;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
function convert(objectPath) {
|
|
59
|
+
const {
|
|
60
|
+
key,
|
|
61
|
+
value,
|
|
62
|
+
} = objectPath.node.properties[0];
|
|
63
|
+
|
|
64
|
+
replaceWith(objectPath, ObjectExpression([
|
|
65
|
+
ObjectProperty(Identifier('plugins'), ArrayExpression([
|
|
66
|
+
ArrayExpression([
|
|
67
|
+
key,
|
|
68
|
+
value,
|
|
69
|
+
]),
|
|
70
|
+
])),
|
|
71
|
+
]));
|
|
72
|
+
}
|
package/lib/declare/index.js
CHANGED
package/lib/declare/operator.js
CHANGED
package/lib/declare/types.json
CHANGED
package/lib/includer/index.js
CHANGED
|
@@ -5,10 +5,8 @@ module.exports.report = () => 'Includer functions should return array (https://g
|
|
|
5
5
|
module.exports.replace = () => ({
|
|
6
6
|
'module.exports.include = () => "__a"': 'module.exports.include = ["__a"]',
|
|
7
7
|
'module.exports.exclude = () => "__a"': 'module.exports.exclude = ["__a"]',
|
|
8
|
-
|
|
9
8
|
'module.exports.include = ["__a"]': 'module.exports.include = () => ["__a"]',
|
|
10
9
|
'module.exports.exclude = ["__a"]': 'module.exports.exclude = () => ["__a"]',
|
|
11
|
-
|
|
12
10
|
'module.exports.include = "__a"': 'module.exports.include = ["__a"]',
|
|
13
11
|
'module.exports.exclude = "__a"': 'module.exports.exclude= ["__a"]',
|
|
14
12
|
});
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const justCamelCase = require('just-camel-case');
|
|
4
|
+
|
|
4
5
|
const {
|
|
5
6
|
types,
|
|
6
7
|
template,
|
|
@@ -60,8 +61,11 @@ module.exports.replace = () => ({
|
|
|
60
61
|
const buildRequire = template(`const NAME = REQUIRE`);
|
|
61
62
|
|
|
62
63
|
function declareRequire({__a, __b}, path) {
|
|
63
|
-
const shortName =
|
|
64
|
+
const shortName = __a.value || __a.name
|
|
65
|
+
.split('/').pop();
|
|
66
|
+
|
|
64
67
|
const name = justCamelCase(shortName);
|
|
68
|
+
|
|
65
69
|
const requireNode = buildRequire({
|
|
66
70
|
NAME: Identifier(name),
|
|
67
71
|
REQUIRE: __b,
|
|
@@ -70,9 +74,10 @@ function declareRequire({__a, __b}, path) {
|
|
|
70
74
|
if (path.scope.hasBinding(name))
|
|
71
75
|
return name;
|
|
72
76
|
|
|
73
|
-
const programPath = path.scope
|
|
77
|
+
const programPath = path.scope
|
|
78
|
+
.getProgramParent().path;
|
|
79
|
+
|
|
74
80
|
programPath.node.body.unshift(requireNode);
|
|
75
81
|
|
|
76
82
|
return name;
|
|
77
83
|
}
|
|
78
|
-
|
|
@@ -58,16 +58,22 @@ function isCorrect({path, incorrect}) {
|
|
|
58
58
|
const calleePath = path.findParent(isCallExpression);
|
|
59
59
|
|
|
60
60
|
if (!calleePath)
|
|
61
|
-
return [
|
|
61
|
+
return [
|
|
62
|
+
CORRECT,
|
|
63
|
+
];
|
|
62
64
|
|
|
63
65
|
const messagePath = calleePath.get('arguments.0');
|
|
64
66
|
|
|
65
67
|
if (!messagePath.isStringLiteral())
|
|
66
|
-
return [
|
|
68
|
+
return [
|
|
69
|
+
CORRECT,
|
|
70
|
+
];
|
|
67
71
|
|
|
68
72
|
const {value} = messagePath.node;
|
|
69
73
|
const is = !incorrect.test(value);
|
|
70
74
|
|
|
71
|
-
return [
|
|
75
|
+
return [
|
|
76
|
+
is,
|
|
77
|
+
messagePath,
|
|
78
|
+
];
|
|
72
79
|
}
|
|
73
|
-
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-putout",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.1.1",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "πPutout plugin helps with plugins development",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"c8": "^7.5.0",
|
|
41
41
|
"eslint": "^8.0.1",
|
|
42
42
|
"eslint-plugin-n": "^15.2.4",
|
|
43
|
-
"eslint-plugin-putout": "^
|
|
43
|
+
"eslint-plugin-putout": "^17.0.0",
|
|
44
44
|
"lerna": "^6.0.1",
|
|
45
45
|
"madrun": "^9.0.0",
|
|
46
46
|
"montag": "^1.2.1",
|