@putout/plugin-putout 22.0.0 → 22.2.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
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);
|
|
@@ -62,6 +63,7 @@ npm i @putout/plugin-putout -D
|
|
|
62
63
|
- ✅ [move-require-on-top-level](#move-require-on-top-level);
|
|
63
64
|
- ✅ [remove-empty-array-from-process](#remove-empty-array-from-process);
|
|
64
65
|
- ✅ [remove-unused-get-properties-argument](#remove-unused-get-properties-argument);
|
|
66
|
+
- ✅ [remove-useless-printer-option](#remove-useless-printer-option);
|
|
65
67
|
- ✅ [rename-operate-to-operator](#rename-operate-to-operator);
|
|
66
68
|
- ✅ [replace-operate-with-operator](#replace-operate-with-operator);
|
|
67
69
|
- ✅ [replace-test-message](#replace-test-message);
|
|
@@ -75,6 +77,7 @@ npm i @putout/plugin-putout -D
|
|
|
75
77
|
"rules": {
|
|
76
78
|
"putout/add-places-to-compare-places": "on",
|
|
77
79
|
"putout/add-path-arg-to-fix": "on",
|
|
80
|
+
"putout/add-path-arg-to-visitors": "on",
|
|
78
81
|
"putout/add-test-args": "on",
|
|
79
82
|
"putout/add-traverse-args": "on",
|
|
80
83
|
"putout/add-track-file": "on",
|
|
@@ -125,6 +128,7 @@ npm i @putout/plugin-putout -D
|
|
|
125
128
|
"putout/replace-test-message": "on",
|
|
126
129
|
"putout/remove-unused-get-properties-argument": "on",
|
|
127
130
|
"putout/remove-empty-array-from-process": "on",
|
|
131
|
+
"putout/remove-useless-printer-option": "on",
|
|
128
132
|
"putout/simplify-replace-template": "on"
|
|
129
133
|
}
|
|
130
134
|
}
|
|
@@ -864,6 +868,30 @@ export const fix = (path) => {
|
|
|
864
868
|
};
|
|
865
869
|
```
|
|
866
870
|
|
|
871
|
+
## add-path-arg-to-visitors
|
|
872
|
+
|
|
873
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e20eb16668b2ebbceca1a03cde859e93/fee08d6dbb6aa4d835adacc8e9de4d994fd34848).
|
|
874
|
+
|
|
875
|
+
### ❌ Example of incorrect code
|
|
876
|
+
|
|
877
|
+
```js
|
|
878
|
+
export const traverse = () => ({
|
|
879
|
+
TSUnionType() {
|
|
880
|
+
console.log(path);
|
|
881
|
+
},
|
|
882
|
+
});
|
|
883
|
+
```
|
|
884
|
+
|
|
885
|
+
### ✅ Example of correct code
|
|
886
|
+
|
|
887
|
+
```js
|
|
888
|
+
export const traverse = () => ({
|
|
889
|
+
TSUnionType(path) {
|
|
890
|
+
console.log(path);
|
|
891
|
+
},
|
|
892
|
+
});
|
|
893
|
+
```
|
|
894
|
+
|
|
867
895
|
## add-test-args
|
|
868
896
|
|
|
869
897
|
### ❌ Example of incorrect code
|
|
@@ -1345,6 +1373,32 @@ const {
|
|
|
1345
1373
|
} = getProperties(__jsonPath, ['parser', 'rules', 'extends']);
|
|
1346
1374
|
```
|
|
1347
1375
|
|
|
1376
|
+
## remove-useless-printer-option
|
|
1377
|
+
|
|
1378
|
+
Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/f176313cf67fd6d7138470385511319f/5b26aa45db21f250016d228b7bbabbb3c10b582b).
|
|
1379
|
+
`putout` printer used by default, so there is no need to pass it.
|
|
1380
|
+
|
|
1381
|
+
### ❌ Example of incorrect code
|
|
1382
|
+
|
|
1383
|
+
```js
|
|
1384
|
+
const test = createTest(__dirname, {
|
|
1385
|
+
printer: 'putout',
|
|
1386
|
+
plugins: [
|
|
1387
|
+
['remove-unchanged-zero-declarations', plugin],
|
|
1388
|
+
],
|
|
1389
|
+
});
|
|
1390
|
+
```
|
|
1391
|
+
|
|
1392
|
+
### ✅ Example of correct code
|
|
1393
|
+
|
|
1394
|
+
```js
|
|
1395
|
+
const test = createTest(__dirname, {
|
|
1396
|
+
plugins: [
|
|
1397
|
+
['remove-unchanged-zero-declarations', plugin],
|
|
1398
|
+
],
|
|
1399
|
+
});
|
|
1400
|
+
```
|
|
1401
|
+
|
|
1348
1402
|
## simplify-replace-template
|
|
1349
1403
|
|
|
1350
1404
|
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/a012fc12f4d38038da022f7c8f379fe2/c65bf97c42650aa31c5481849bc934323df892a6).
|
|
@@ -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
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -54,6 +54,8 @@ const removeEmptyArrayFromProcess = require('./remove-empty-array-from-process')
|
|
|
54
54
|
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
|
+
const removeUselessPrinterOption = require('./remove-useless-printer-option');
|
|
58
|
+
const addPathArgToVisitors = require('./add-path-arg-to-visitors');
|
|
57
59
|
|
|
58
60
|
module.exports.rules = {
|
|
59
61
|
'apply-processors-destructuring': applyProcessorsDestructuring,
|
|
@@ -110,4 +112,6 @@ module.exports.rules = {
|
|
|
110
112
|
'add-places-to-compare-places': addPlacesToComparePlaces,
|
|
111
113
|
'add-path-arg-to-fix': addPathArgToFix,
|
|
112
114
|
'convert-include-to-traverse': convertIncludeToTraverse,
|
|
115
|
+
'remove-useless-printer-option': removeUselessPrinterOption,
|
|
116
|
+
'add-path-arg-to-visitors': addPathArgToVisitors,
|
|
113
117
|
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {operator, types} = require('putout');
|
|
4
|
+
const {
|
|
5
|
+
isCallExpression,
|
|
6
|
+
isIdentifier,
|
|
7
|
+
} = types;
|
|
8
|
+
|
|
9
|
+
const {remove} = operator;
|
|
10
|
+
|
|
11
|
+
module.exports.report = () => `Avoid useless 'printer' option`;
|
|
12
|
+
|
|
13
|
+
module.exports.fix = (path) => {
|
|
14
|
+
remove(path);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
module.exports.traverse = ({push}) => ({
|
|
18
|
+
ObjectProperty(path) {
|
|
19
|
+
const {value} = path.node;
|
|
20
|
+
|
|
21
|
+
if (value.value !== 'putout')
|
|
22
|
+
return;
|
|
23
|
+
|
|
24
|
+
const {parentPath} = path.parentPath;
|
|
25
|
+
|
|
26
|
+
if (!isCallExpression(parentPath))
|
|
27
|
+
return;
|
|
28
|
+
|
|
29
|
+
const name = 'createTest';
|
|
30
|
+
|
|
31
|
+
if (!isIdentifier(parentPath.node.callee, {name}))
|
|
32
|
+
return;
|
|
33
|
+
|
|
34
|
+
push(path);
|
|
35
|
+
},
|
|
36
|
+
});
|
package/package.json
CHANGED