@putout/plugin-putout 22.1.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);
|
|
@@ -76,6 +77,7 @@ npm i @putout/plugin-putout -D
|
|
|
76
77
|
"rules": {
|
|
77
78
|
"putout/add-places-to-compare-places": "on",
|
|
78
79
|
"putout/add-path-arg-to-fix": "on",
|
|
80
|
+
"putout/add-path-arg-to-visitors": "on",
|
|
79
81
|
"putout/add-test-args": "on",
|
|
80
82
|
"putout/add-traverse-args": "on",
|
|
81
83
|
"putout/add-track-file": "on",
|
|
@@ -866,6 +868,30 @@ export const fix = (path) => {
|
|
|
866
868
|
};
|
|
867
869
|
```
|
|
868
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
|
+
|
|
869
895
|
## add-test-args
|
|
870
896
|
|
|
871
897
|
### ❌ Example of incorrect code
|
|
@@ -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
|
@@ -55,6 +55,7 @@ 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');
|
|
58
59
|
|
|
59
60
|
module.exports.rules = {
|
|
60
61
|
'apply-processors-destructuring': applyProcessorsDestructuring,
|
|
@@ -112,4 +113,5 @@ module.exports.rules = {
|
|
|
112
113
|
'add-path-arg-to-fix': addPathArgToFix,
|
|
113
114
|
'convert-include-to-traverse': convertIncludeToTraverse,
|
|
114
115
|
'remove-useless-printer-option': removeUselessPrinterOption,
|
|
116
|
+
'add-path-arg-to-visitors': addPathArgToVisitors,
|
|
115
117
|
};
|
package/package.json
CHANGED