@putout/plugin-putout 11.1.0 → 11.3.0
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 +69 -4
- package/lib/add-args/index.js +12 -2
- package/lib/apply-remove/index.js +8 -0
- package/lib/convert-putout-test-to-create-test/index.js +10 -0
- package/lib/declare/operator.js +1 -0
- package/lib/index.js +2 -0
- package/lib/replace-test-message/index.js +74 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ npm i @putout/plugin-putout -D
|
|
|
19
19
|
"putout/apply-create-test": "on",
|
|
20
20
|
"putout/apply-processors-destructuring": "on",
|
|
21
21
|
"putout/apply-async-formatter": "on",
|
|
22
|
+
"putout/apply-remove": "on",
|
|
22
23
|
"putout/add-args": "on",
|
|
23
24
|
"putout/add-push": "on",
|
|
24
25
|
"putout/convert-putout-test-to-create-test": "on",
|
|
@@ -41,7 +42,8 @@ npm i @putout/plugin-putout -D
|
|
|
41
42
|
"putout/check-replace-code": "on",
|
|
42
43
|
"putout/declare": "on",
|
|
43
44
|
"putout/includer": "on",
|
|
44
|
-
"putout/move-require-on-top-level": "on"
|
|
45
|
+
"putout/move-require-on-top-level": "on",
|
|
46
|
+
"putout/replace-test-message": "on"
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
```
|
|
@@ -65,6 +67,30 @@ test('', async ({process}) => {
|
|
|
65
67
|
});
|
|
66
68
|
```
|
|
67
69
|
|
|
70
|
+
## apply-remove
|
|
71
|
+
|
|
72
|
+
Better to use [`remove(path)`](https://github.com/coderaiser/putout/tree/master/packages/operate#removepath) method of `operator`.
|
|
73
|
+
It helps to preserve comments.
|
|
74
|
+
|
|
75
|
+
### ❌ Example of incorrect code
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
export const fix = (path) => {
|
|
79
|
+
path.remove();
|
|
80
|
+
};
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### ✅ Example of correct code
|
|
84
|
+
|
|
85
|
+
```js
|
|
86
|
+
import {operator} from 'putout';
|
|
87
|
+
const {remove} = operator;
|
|
88
|
+
|
|
89
|
+
export const fix = (path) => {
|
|
90
|
+
remove(path);
|
|
91
|
+
};
|
|
92
|
+
```
|
|
93
|
+
|
|
68
94
|
## apply-async-formatter
|
|
69
95
|
|
|
70
96
|
### ❌ Example of incorrect code
|
|
@@ -120,7 +146,7 @@ const test = putoutTest(__dirname, {
|
|
|
120
146
|
### ✅ Example of correct code
|
|
121
147
|
|
|
122
148
|
```js
|
|
123
|
-
import createTest from '@putout/test';
|
|
149
|
+
import {createTest} from '@putout/test';
|
|
124
150
|
|
|
125
151
|
const test = createTest(__dirname, {
|
|
126
152
|
'remove-unused-variables': rmVars,
|
|
@@ -392,7 +418,7 @@ module.exports.replace = () => ({
|
|
|
392
418
|
});
|
|
393
419
|
```
|
|
394
420
|
|
|
395
|
-
There is no `fix` for this rule, it used internally to be more confident about `test coverage`, because of declaration form, transforms cannon be checked by `nyc` and `c8`, and uncovered lines can find unfixable false
|
|
421
|
+
There is no `fix` for this rule, it used internally to be more confident about `test coverage`, because of declaration form, transforms cannon be checked by `nyc` and `c8`, and uncovered lines can find unfixable false positives when running on code.
|
|
396
422
|
This is additional tests, if you forget to test some case (from a big list of rules that is supported) it will be checked with this `rule` and make transforms more stable.
|
|
397
423
|
|
|
398
424
|
## declare
|
|
@@ -460,6 +486,8 @@ module.exports.traverse = ({push}) => ({
|
|
|
460
486
|
|
|
461
487
|
## convert-add-argument-to-add-args
|
|
462
488
|
|
|
489
|
+
### ❌ Example of incorrect code
|
|
490
|
+
|
|
463
491
|
```js
|
|
464
492
|
const {operator} = require('putout');
|
|
465
493
|
const {addArgument} = operator;
|
|
@@ -482,6 +510,8 @@ module.exports = addArgs({
|
|
|
482
510
|
|
|
483
511
|
## convert-dirname-to-url
|
|
484
512
|
|
|
513
|
+
### ❌ Example of incorrect code
|
|
514
|
+
|
|
485
515
|
```js
|
|
486
516
|
import {createTest} from '@putout/test';
|
|
487
517
|
import plugin from '@putout/plugin-debugger';
|
|
@@ -506,11 +536,13 @@ const test = createTest(import.meta.url, {
|
|
|
506
536
|
|
|
507
537
|
## convert-url-to-dirname-
|
|
508
538
|
|
|
539
|
+
### ❌ Example of incorrect code
|
|
540
|
+
|
|
509
541
|
```js
|
|
510
542
|
const {createTest} = require('@putout/test');
|
|
511
543
|
const plugin = require('@putout/plugin-debugger');
|
|
512
544
|
|
|
513
|
-
const test = createTest(
|
|
545
|
+
const test = createTest(__dirname, {
|
|
514
546
|
'remove-debugger': plugin,
|
|
515
547
|
});
|
|
516
548
|
```
|
|
@@ -587,6 +619,39 @@ module.exports.include = () => ['cons __a = __b'];
|
|
|
587
619
|
module.exports.exclude = () => ['var __a = __b'];
|
|
588
620
|
```
|
|
589
621
|
|
|
622
|
+
## replace-test-message
|
|
623
|
+
|
|
624
|
+
Checks that `test message` and used `operator` are synchronized.
|
|
625
|
+
Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d9c6972ea848ba8e7e745d2479727b65/199c30b986ce7d544397c344ebfc5031c4b53181).
|
|
626
|
+
|
|
627
|
+
### ❌ Example of incorrect code
|
|
628
|
+
|
|
629
|
+
```js
|
|
630
|
+
test('plugin-putout: rename-operate-to-operator: transform: operator exist', (t) => {
|
|
631
|
+
t.noTransform('operator');
|
|
632
|
+
t.end();
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
test('plugin-putout: rename-operate-to-operator: report: operator exist', (t) => {
|
|
636
|
+
t.noReport('operator');
|
|
637
|
+
t.end();
|
|
638
|
+
});
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
### ✅ Example of correct code
|
|
642
|
+
|
|
643
|
+
```js
|
|
644
|
+
test('plugin-putout: rename-operate-to-operator: no transform: operator exist', (t) => {
|
|
645
|
+
t.noTransform('operator');
|
|
646
|
+
t.end();
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
test('plugin-putout: rename-operate-to-operator: no report: operator exist', (t) => {
|
|
650
|
+
t.noReport('operator');
|
|
651
|
+
t.end();
|
|
652
|
+
});
|
|
653
|
+
```
|
|
654
|
+
|
|
590
655
|
## License
|
|
591
656
|
|
|
592
657
|
MIT
|
package/lib/add-args/index.js
CHANGED
|
@@ -4,7 +4,17 @@ const {operator} = require('putout');
|
|
|
4
4
|
const {addArgs} = operator;
|
|
5
5
|
|
|
6
6
|
module.exports = addArgs({
|
|
7
|
-
comparePlaces: ['{comparePlaces}',
|
|
8
|
-
|
|
7
|
+
comparePlaces: ['{comparePlaces}', [
|
|
8
|
+
'test("__a", async (__args) => __body)',
|
|
9
|
+
'test.skip("__a", async (__args) => __body)',
|
|
10
|
+
'test.only("__a", async (__args) => __body)',
|
|
11
|
+
],
|
|
12
|
+
],
|
|
13
|
+
process: ['{process}', [
|
|
14
|
+
'test("__a", async (__args) => __body)',
|
|
15
|
+
'test.skip("__a", async (__args) => __body)',
|
|
16
|
+
'test.only("__a", async (__args) => __body)',
|
|
17
|
+
],
|
|
18
|
+
],
|
|
9
19
|
});
|
|
10
20
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {assign} = Object;
|
|
4
|
+
|
|
3
5
|
module.exports.report = () => `Use 'createTest' instead of 'putoutTest'`;
|
|
4
6
|
|
|
5
7
|
module.exports.filter = ({scope}) => !scope.bindings.createTest;
|
|
@@ -9,6 +11,14 @@ module.exports.include = () => [
|
|
|
9
11
|
];
|
|
10
12
|
|
|
11
13
|
module.exports.fix = (path) => {
|
|
14
|
+
const [first] = path.node.specifiers;
|
|
15
|
+
|
|
16
|
+
assign(first, {
|
|
17
|
+
type: 'ImportSpecifier',
|
|
18
|
+
kind: 'value',
|
|
19
|
+
imported: first.local,
|
|
20
|
+
});
|
|
21
|
+
|
|
12
22
|
path.scope.rename('putoutTest', 'createTest');
|
|
13
23
|
};
|
|
14
24
|
|
package/lib/declare/operator.js
CHANGED
|
@@ -13,6 +13,7 @@ module.exports = {
|
|
|
13
13
|
addArgs: `const {addArgs} = operator`,
|
|
14
14
|
replaceWith: `const {replaceWith} = operator`,
|
|
15
15
|
replaceWithMultiple: `const {replaceWithMultiple} = operator`,
|
|
16
|
+
remove: 'const {remove} = operator',
|
|
16
17
|
isESM: `const {isESM} = operator`,
|
|
17
18
|
getProperty: `const {getProperty} = operator`,
|
|
18
19
|
getProperties: `const {getProperties} = operator`,
|
package/lib/index.js
CHANGED
|
@@ -8,6 +8,7 @@ module.exports.rules = {
|
|
|
8
8
|
...getRule('apply-processors-destructuring'),
|
|
9
9
|
...getRule('apply-async-formatter'),
|
|
10
10
|
...getRule('apply-create-test'),
|
|
11
|
+
...getRule('apply-remove'),
|
|
11
12
|
...getRule('convert-putout-test-to-create-test'),
|
|
12
13
|
...getRule('convert-to-no-transform-code'),
|
|
13
14
|
...getRule('convert-find-to-traverse'),
|
|
@@ -25,6 +26,7 @@ module.exports.rules = {
|
|
|
25
26
|
...getRule('convert-add-argument-to-add-args'),
|
|
26
27
|
...getRule('convert-dirname-to-url'),
|
|
27
28
|
...getRule('convert-url-to-dirname'),
|
|
29
|
+
...getRule('replace-test-message'),
|
|
28
30
|
...getRule('rename-operate-to-operator'),
|
|
29
31
|
...getRule('replace-operate-with-operator'),
|
|
30
32
|
...getRule('shorten-imports'),
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types} = require('putout');
|
|
4
|
+
|
|
5
|
+
const {isCallExpression} = types;
|
|
6
|
+
|
|
7
|
+
module.exports.report = ({correct, operatorPath}) => {
|
|
8
|
+
const calleePath = operatorPath.get('callee');
|
|
9
|
+
return `Use '${correct}' in test message when using '${calleePath}()'`;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
module.exports.fix = ({path, incorrect, correct}) => {
|
|
13
|
+
path.node.value = path.node.value.replace(incorrect, correct);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
module.exports.traverse = ({push}) => ({
|
|
17
|
+
't.transform(__a)': convert({
|
|
18
|
+
push,
|
|
19
|
+
incorrect: /: no transform/,
|
|
20
|
+
correct: ': transform',
|
|
21
|
+
}),
|
|
22
|
+
't.noTransform(__a)': convert({
|
|
23
|
+
push,
|
|
24
|
+
incorrect: /: transform/,
|
|
25
|
+
correct: ': no transform',
|
|
26
|
+
}),
|
|
27
|
+
't.report(__a)': convert({
|
|
28
|
+
push,
|
|
29
|
+
incorrect: /: no report/,
|
|
30
|
+
correct: ': report',
|
|
31
|
+
}),
|
|
32
|
+
't.noReport(__a)': convert({
|
|
33
|
+
push,
|
|
34
|
+
incorrect: /: (report|transform|no transform)/,
|
|
35
|
+
correct: ': no report',
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const convert = ({push, correct, incorrect}) => (path) => {
|
|
40
|
+
const [is, messagePath] = isCorrect({
|
|
41
|
+
incorrect,
|
|
42
|
+
path,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
if (is)
|
|
46
|
+
return;
|
|
47
|
+
|
|
48
|
+
push({
|
|
49
|
+
path: messagePath,
|
|
50
|
+
operatorPath: path,
|
|
51
|
+
incorrect,
|
|
52
|
+
correct,
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const CORRECT = true;
|
|
57
|
+
|
|
58
|
+
function isCorrect({path, incorrect}) {
|
|
59
|
+
const calleePath = path.findParent(isCallExpression);
|
|
60
|
+
|
|
61
|
+
if (!calleePath)
|
|
62
|
+
return [CORRECT];
|
|
63
|
+
|
|
64
|
+
const messagePath = calleePath.get('arguments.0');
|
|
65
|
+
|
|
66
|
+
if (!messagePath.isStringLiteral())
|
|
67
|
+
return [CORRECT];
|
|
68
|
+
|
|
69
|
+
const {value} = messagePath.node;
|
|
70
|
+
const is = !incorrect.test(value);
|
|
71
|
+
|
|
72
|
+
return [is, messagePath];
|
|
73
|
+
}
|
|
74
|
+
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-putout",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.3.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
|
-
"description": "
|
|
6
|
+
"description": "🐊Putout plugin helps with plugins development",
|
|
7
7
|
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-putout#readme",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"release": false,
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"c8": "^7.5.0",
|
|
41
41
|
"eslint": "^8.0.1",
|
|
42
42
|
"eslint-plugin-node": "^11.0.0",
|
|
43
|
-
"eslint-plugin-putout": "^
|
|
43
|
+
"eslint-plugin-putout": "^15.0.0",
|
|
44
44
|
"lerna": "^4.0.0",
|
|
45
45
|
"madrun": "^9.0.0",
|
|
46
46
|
"montag": "^1.2.1",
|