@putout/plugin-putout 22.1.0 → 22.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 +49 -1
- package/lib/add-path-arg-to-visitors/index.js +46 -0
- package/lib/add-traverse-args/index.js +3 -7
- package/lib/apply-fixture-name-to-message/index.js +70 -0
- package/lib/convert-babel-types/index.js +7 -15
- package/lib/convert-progress-to-track-file/index.js +1 -5
- package/lib/index.js +4 -0
- package/lib/remove-useless-printer-option/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,6 +17,7 @@ npm i @putout/plugin-putout -D
|
|
|
17
17
|
- ✅ [add-index-to-import](#add-index-to-import);
|
|
18
18
|
- ✅ [add-places-to-compare-places](#add-places-to-compare-places);
|
|
19
19
|
- ✅ [add-path-arg-to-fix](#add-path-arg-to-fix);
|
|
20
|
+
- ✅ [add-path-arg-to-visitors](#add-path-arg-to-visitors);
|
|
20
21
|
- ✅ [add-test-args](#add-test-args);
|
|
21
22
|
- ✅ [add-traverse-args](#add-traverse-args);
|
|
22
23
|
- ✅ [add-track-file](#add-track-file);
|
|
@@ -24,6 +25,7 @@ npm i @putout/plugin-putout -D
|
|
|
24
25
|
- ✅ [apply-create-test](#apply-create-test);
|
|
25
26
|
- ✅ [apply-declare](#apply-declare);
|
|
26
27
|
- ✅ [apply-for-of-to-track-file](#apply-for-of-to-track-file);
|
|
28
|
+
- ✅ [apply-fixture-name-to-message](#apply-fixture-name-to-message);
|
|
27
29
|
- ✅ [apply-insert-after](#apply-insert-after);
|
|
28
30
|
- ✅ [apply-insert-before](#apply-insert-before);
|
|
29
31
|
- ✅ [apply-namespace-specifier](#apply-namespace-specifier);
|
|
@@ -76,15 +78,16 @@ npm i @putout/plugin-putout -D
|
|
|
76
78
|
"rules": {
|
|
77
79
|
"putout/add-places-to-compare-places": "on",
|
|
78
80
|
"putout/add-path-arg-to-fix": "on",
|
|
81
|
+
"putout/add-path-arg-to-visitors": "on",
|
|
79
82
|
"putout/add-test-args": "on",
|
|
80
83
|
"putout/add-traverse-args": "on",
|
|
81
84
|
"putout/add-track-file": "on",
|
|
82
85
|
"putout/add-await-to-progress": "on",
|
|
83
86
|
"putout/add-index-to-import": "on",
|
|
84
87
|
"putout/apply-create-test": "on",
|
|
85
|
-
"putout/apply-processors-destructuring": "on",
|
|
86
88
|
"putout/apply-async-formatter": "on",
|
|
87
89
|
"putout/apply-declare": "on",
|
|
90
|
+
"putout/apply-processors-destructuring": "on",
|
|
88
91
|
"putout/apply-rename": "on",
|
|
89
92
|
"putout/apply-remove": "on",
|
|
90
93
|
"putout/apply-insert-before": "on",
|
|
@@ -92,6 +95,7 @@ npm i @putout/plugin-putout -D
|
|
|
92
95
|
"putout/apply-short-processors": "on",
|
|
93
96
|
"putout/apply-namespace-specifier": "on",
|
|
94
97
|
"putout/apply-for-of-to-track-file": "on",
|
|
98
|
+
"putout/apply-fixture-name-to-message": "on",
|
|
95
99
|
"putout/check-match": "on",
|
|
96
100
|
"putout/check-replace-code": ["on", {
|
|
97
101
|
"once": true
|
|
@@ -866,6 +870,30 @@ export const fix = (path) => {
|
|
|
866
870
|
};
|
|
867
871
|
```
|
|
868
872
|
|
|
873
|
+
## add-path-arg-to-visitors
|
|
874
|
+
|
|
875
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e20eb16668b2ebbceca1a03cde859e93/fee08d6dbb6aa4d835adacc8e9de4d994fd34848).
|
|
876
|
+
|
|
877
|
+
### ❌ Example of incorrect code
|
|
878
|
+
|
|
879
|
+
```js
|
|
880
|
+
export const traverse = () => ({
|
|
881
|
+
TSUnionType() {
|
|
882
|
+
console.log(path);
|
|
883
|
+
},
|
|
884
|
+
});
|
|
885
|
+
```
|
|
886
|
+
|
|
887
|
+
### ✅ Example of correct code
|
|
888
|
+
|
|
889
|
+
```js
|
|
890
|
+
export const traverse = () => ({
|
|
891
|
+
TSUnionType(path) {
|
|
892
|
+
console.log(path);
|
|
893
|
+
},
|
|
894
|
+
});
|
|
895
|
+
```
|
|
896
|
+
|
|
869
897
|
## add-test-args
|
|
870
898
|
|
|
871
899
|
### ❌ Example of incorrect code
|
|
@@ -1393,6 +1421,26 @@ module.exports.replace = () => ({
|
|
|
1393
1421
|
});
|
|
1394
1422
|
```
|
|
1395
1423
|
|
|
1424
|
+
## apply-fixture-name-to-message"
|
|
1425
|
+
|
|
1426
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/66eb493ee966c2465a9fc783cd3ca362/f42ec60e393181b6d6aaf6df81640e93fabe8783).
|
|
1427
|
+
|
|
1428
|
+
```js
|
|
1429
|
+
test('flatlint: convert-comma-to-semicolon: no report: xxx', (t) => {
|
|
1430
|
+
t.noReport('array');
|
|
1431
|
+
t.end();
|
|
1432
|
+
});
|
|
1433
|
+
```
|
|
1434
|
+
|
|
1435
|
+
### ✅ Example of correct code
|
|
1436
|
+
|
|
1437
|
+
```js
|
|
1438
|
+
test('flatlint: convert-comma-to-semicolon: no report: array', (t) => {
|
|
1439
|
+
t.noReport('array');
|
|
1440
|
+
t.end();
|
|
1441
|
+
});
|
|
1442
|
+
```
|
|
1443
|
+
|
|
1396
1444
|
## License
|
|
1397
1445
|
|
|
1398
1446
|
MIT
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types} = require('putout');
|
|
4
|
+
const {Identifier} = types;
|
|
5
|
+
|
|
6
|
+
module.exports.report = () => `Add 'path' argument to 'traverse' visitors`;
|
|
7
|
+
|
|
8
|
+
const TRAVERSE = '(__args) => __object';
|
|
9
|
+
|
|
10
|
+
module.exports.fix = (path) => {
|
|
11
|
+
path.node.params.push(Identifier('path'));
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
module.exports.traverse = ({push}) => ({
|
|
15
|
+
[`export const traverse = ${TRAVERSE}`]: traverseMethods({
|
|
16
|
+
where: 'declaration.declarations.0.init',
|
|
17
|
+
push,
|
|
18
|
+
}),
|
|
19
|
+
[`module.exports.traverse = ${TRAVERSE}`]: traverseMethods({
|
|
20
|
+
where: 'right',
|
|
21
|
+
push,
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const traverseMethods = ({where, push}) => (path) => {
|
|
26
|
+
const initPath = path.get(where);
|
|
27
|
+
const objectPath = initPath.get('body');
|
|
28
|
+
|
|
29
|
+
for (let prop of objectPath.get('properties')) {
|
|
30
|
+
if (prop.isObjectProperty())
|
|
31
|
+
prop = prop.get('value');
|
|
32
|
+
|
|
33
|
+
if (!prop.isFunction())
|
|
34
|
+
continue;
|
|
35
|
+
|
|
36
|
+
if (prop.node.params.length)
|
|
37
|
+
continue;
|
|
38
|
+
|
|
39
|
+
prop.traverse({
|
|
40
|
+
ReferencedIdentifier(path) {
|
|
41
|
+
if (path.node.name === 'path')
|
|
42
|
+
push(prop);
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
};
|
|
@@ -107,10 +107,6 @@ function parseFn(path) {
|
|
|
107
107
|
return path.get('declaration.declarations.0.init').node;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
.isIdentifier({
|
|
114
|
-
name,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
110
|
+
const isCallee = (name, {parentPath}) => parentPath.get('callee').isIdentifier({
|
|
111
|
+
name,
|
|
112
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {operator} = require('putout');
|
|
4
|
+
const {
|
|
5
|
+
setLiteralValue,
|
|
6
|
+
compare,
|
|
7
|
+
} = operator;
|
|
8
|
+
|
|
9
|
+
const FIXTURE = [
|
|
10
|
+
'report',
|
|
11
|
+
'transform',
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
const NAMES = [
|
|
15
|
+
...FIXTURE,
|
|
16
|
+
'no report',
|
|
17
|
+
'no transform',
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
module.exports.report = () => `Apply 'fixture' name to 'message'`;
|
|
21
|
+
|
|
22
|
+
module.exports.match = () => ({
|
|
23
|
+
't.noReport(__a)': check,
|
|
24
|
+
't.report(__a, __b)': check,
|
|
25
|
+
't.transform(__a)': check,
|
|
26
|
+
't.noTransform(__a)': check,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
module.exports.replace = () => ({
|
|
30
|
+
't.noReport(__a)': transform,
|
|
31
|
+
't.report(__a, __b)': transform,
|
|
32
|
+
't.transform(__a)': transform,
|
|
33
|
+
't.noTransform(__a)': transform,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const isTest = (path) => compare(path, 'test(__a, (t) => __body)');
|
|
37
|
+
|
|
38
|
+
const check = ({__a}, path) => {
|
|
39
|
+
const name = __a.value;
|
|
40
|
+
|
|
41
|
+
if (FIXTURE.includes(name))
|
|
42
|
+
return false;
|
|
43
|
+
|
|
44
|
+
const testPath = path.find(isTest);
|
|
45
|
+
|
|
46
|
+
if (!testPath)
|
|
47
|
+
return false;
|
|
48
|
+
|
|
49
|
+
const [str] = testPath.parentPath.parentPath.node.arguments;
|
|
50
|
+
|
|
51
|
+
return !str.value.includes(name);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const transform = ({__a}, path) => {
|
|
55
|
+
const name = __a.value;
|
|
56
|
+
const testPath = path.find(isTest);
|
|
57
|
+
const [str] = testPath.parentPath.parentPath.node.arguments;
|
|
58
|
+
|
|
59
|
+
const values = str.value.split(':');
|
|
60
|
+
const last = values
|
|
61
|
+
.at(-1)
|
|
62
|
+
.trim();
|
|
63
|
+
|
|
64
|
+
if (!NAMES.includes(last))
|
|
65
|
+
values.pop();
|
|
66
|
+
|
|
67
|
+
setLiteralValue(str, `${values.join(':')}: ${name}`);
|
|
68
|
+
|
|
69
|
+
return path;
|
|
70
|
+
};
|
|
@@ -12,21 +12,13 @@ module.exports.report = () => {
|
|
|
12
12
|
return `"putout.types" should be used instead of "@babel/types"`;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function isBabelTypes(path) {
|
|
24
|
-
return path
|
|
25
|
-
.get('arguments.0')
|
|
26
|
-
.isStringLiteral({
|
|
27
|
-
value: '@babel/types',
|
|
28
|
-
});
|
|
29
|
-
}
|
|
15
|
+
const isRequire = (path) => path.get('callee').isIdentifier({
|
|
16
|
+
name: 'require',
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const isBabelTypes = (path) => path.get('arguments.0').isStringLiteral({
|
|
20
|
+
value: '@babel/types',
|
|
21
|
+
});
|
|
30
22
|
|
|
31
23
|
module.exports.traverse = ({push}) => ({
|
|
32
24
|
CallExpression(path) {
|
|
@@ -29,11 +29,7 @@ module.exports.traverse = ({push}) => ({
|
|
|
29
29
|
if (!statement)
|
|
30
30
|
return;
|
|
31
31
|
|
|
32
|
-
const forOfCount = statement
|
|
33
|
-
.parentPath
|
|
34
|
-
.get('body')
|
|
35
|
-
.filter(isForOfStatement)
|
|
36
|
-
.length;
|
|
32
|
+
const forOfCount = statement.parentPath.get('body').filter(isForOfStatement).length;
|
|
37
33
|
|
|
38
34
|
if (forOfCount > 1)
|
|
39
35
|
return;
|
package/lib/index.js
CHANGED
|
@@ -55,6 +55,8 @@ const addPlacesToComparePlaces = require('./add-places-to-compare-places');
|
|
|
55
55
|
const addPathArgToFix = require('./add-path-arg-to-fix');
|
|
56
56
|
const convertIncludeToTraverse = require('./convert-include-to-traverse');
|
|
57
57
|
const removeUselessPrinterOption = require('./remove-useless-printer-option');
|
|
58
|
+
const addPathArgToVisitors = require('./add-path-arg-to-visitors');
|
|
59
|
+
const applyFixtureNameToMessage = require('./apply-fixture-name-to-message');
|
|
58
60
|
|
|
59
61
|
module.exports.rules = {
|
|
60
62
|
'apply-processors-destructuring': applyProcessorsDestructuring,
|
|
@@ -112,4 +114,6 @@ module.exports.rules = {
|
|
|
112
114
|
'add-path-arg-to-fix': addPathArgToFix,
|
|
113
115
|
'convert-include-to-traverse': convertIncludeToTraverse,
|
|
114
116
|
'remove-useless-printer-option': removeUselessPrinterOption,
|
|
117
|
+
'add-path-arg-to-visitors': addPathArgToVisitors,
|
|
118
|
+
'apply-fixture-name-to-message': applyFixtureNameToMessage,
|
|
115
119
|
};
|
package/package.json
CHANGED