@putout/plugin-putout 19.6.1 → 20.0.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 +14 -15
- package/lib/{add-arg.js → add-traverse-args/index.js} +30 -22
- package/lib/index.js +4 -8
- package/package.json +1 -1
- package/lib/add-path-store/index.js +0 -5
- package/lib/add-push/index.js +0 -5
- package/lib/add-store/index.js +0 -5
- /package/lib/{add-args → add-test-args}/index.js +0 -0
package/README.md
CHANGED
|
@@ -13,12 +13,10 @@ npm i @putout/plugin-putout -D
|
|
|
13
13
|
|
|
14
14
|
## Rules
|
|
15
15
|
|
|
16
|
-
- ✅ [add-args](#add-args);
|
|
16
|
+
- ✅ [add-test-args](#add-test-args);
|
|
17
17
|
- ✅ [add-await-to-progress](#add-await-to-progress);
|
|
18
18
|
- ✅ [add-index-to-import](#add-index-to-import);
|
|
19
|
-
- ✅ [add-
|
|
20
|
-
- ✅ [add-store](#add-store);
|
|
21
|
-
- ✅ [add-path-store](#add-path-store);
|
|
19
|
+
- ✅ [add-traverse-args](#add-traverse-args);
|
|
22
20
|
- ✅ [add-track-file](#add-track-file);
|
|
23
21
|
- ✅ [apply-async-formatter](#apply-async-formatter);
|
|
24
22
|
- ✅ [apply-create-test](#apply-create-test);
|
|
@@ -33,7 +31,7 @@ npm i @putout/plugin-putout -D
|
|
|
33
31
|
- ✅ [apply-short-processors](#apply-short-processors);
|
|
34
32
|
- ✅ [check-match](#check-match);
|
|
35
33
|
- ✅ [check-replace-code](#check-replace-code);
|
|
36
|
-
- ✅ [convert-add-argument-to-add-args](#convert-add-argument-to-add-args);
|
|
34
|
+
- ✅ [convert-add-argument-to-add-args](#convert-add-argument-to-add-test-args);
|
|
37
35
|
- ✅ [convert-babel-types](#convert-babel-types);
|
|
38
36
|
- ✅ [convert-destructuring-to-identifier](#convert-destructuring-to-identifier);
|
|
39
37
|
- ✅ [convert-dirname-to-url](#convert-dirname-to-url);
|
|
@@ -81,10 +79,8 @@ npm i @putout/plugin-putout -D
|
|
|
81
79
|
"putout/apply-short-processors": "on",
|
|
82
80
|
"putout/apply-namespace-specifier": "on",
|
|
83
81
|
"putout/apply-for-of-to-track-file": "on",
|
|
84
|
-
"putout/add-args": "on",
|
|
85
|
-
"putout/add-
|
|
86
|
-
"putout/add-store": "on",
|
|
87
|
-
"putout/add-path-store": "on",
|
|
82
|
+
"putout/add-test-args": "on",
|
|
83
|
+
"putout/add-traverse-args": "on",
|
|
88
84
|
"putout/add-track-file": "on",
|
|
89
85
|
"putout/add-await-to-progress": "on",
|
|
90
86
|
"putout/add-index-to-import": "on",
|
|
@@ -797,7 +793,7 @@ compare(a, 'const __a = __b');
|
|
|
797
793
|
isIdentifier(a);
|
|
798
794
|
```
|
|
799
795
|
|
|
800
|
-
## add-args
|
|
796
|
+
## add-test-args
|
|
801
797
|
|
|
802
798
|
### ❌ Example of incorrect code
|
|
803
799
|
|
|
@@ -815,7 +811,12 @@ test('', ({comparePlaces}) => {
|
|
|
815
811
|
});
|
|
816
812
|
```
|
|
817
813
|
|
|
818
|
-
## add-
|
|
814
|
+
## add-traverse-args
|
|
815
|
+
|
|
816
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/b453bd78b8e9380da8b2f33dfb38b4e2/53b14f89eb88aa10c8e00ba1f0251976592e14ee).
|
|
817
|
+
Supported args:
|
|
818
|
+
|
|
819
|
+
- `push`:
|
|
819
820
|
|
|
820
821
|
### ❌ Example of incorrect code
|
|
821
822
|
|
|
@@ -837,9 +838,7 @@ module.exports.traverse = ({push}) => ({
|
|
|
837
838
|
});
|
|
838
839
|
```
|
|
839
840
|
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/b453bd78b8e9380da8b2f33dfb38b4e2/53b14f89eb88aa10c8e00ba1f0251976592e14ee).
|
|
841
|
+
- `store`
|
|
843
842
|
|
|
844
843
|
### ❌ Example of incorrect code
|
|
845
844
|
|
|
@@ -867,7 +866,7 @@ module.exports.traverse = ({store}) => ({
|
|
|
867
866
|
});
|
|
868
867
|
```
|
|
869
868
|
|
|
870
|
-
|
|
869
|
+
- `pathStore`:
|
|
871
870
|
|
|
872
871
|
### ❌ Example of incorrect code
|
|
873
872
|
|
|
@@ -9,21 +9,19 @@ const {
|
|
|
9
9
|
Identifier,
|
|
10
10
|
} = types;
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
};
|
|
12
|
+
const defaultNames = [
|
|
13
|
+
'push',
|
|
14
|
+
'store',
|
|
15
|
+
'pathStore',
|
|
16
|
+
];
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
module.exports.report = ({name}) => `Add '${name}' argument to 'traverse'`;
|
|
21
19
|
|
|
22
|
-
|
|
20
|
+
module.exports.fix = ({name, fn}) => {
|
|
23
21
|
const computed = false;
|
|
24
22
|
const shorthand = true;
|
|
25
|
-
const
|
|
26
|
-
const property = ObjectProperty(
|
|
23
|
+
const id = Identifier(name);
|
|
24
|
+
const property = ObjectProperty(id, id, computed, shorthand);
|
|
27
25
|
|
|
28
26
|
if (!fn.params.length) {
|
|
29
27
|
fn.params.push(ObjectPattern([property]));
|
|
@@ -33,8 +31,11 @@ const createFix = (mainName) => ({fn}) => {
|
|
|
33
31
|
fn.params[0].properties.push(property);
|
|
34
32
|
};
|
|
35
33
|
|
|
36
|
-
|
|
37
|
-
const
|
|
34
|
+
module.exports.traverse = ({push, options}) => {
|
|
35
|
+
const {
|
|
36
|
+
names = defaultNames,
|
|
37
|
+
} = options;
|
|
38
|
+
const check = checkArgs(names, push);
|
|
38
39
|
|
|
39
40
|
return {
|
|
40
41
|
'export const traverse = (__args) => __': check,
|
|
@@ -54,37 +55,44 @@ const isArgExists = (mainName, fn) => {
|
|
|
54
55
|
return false;
|
|
55
56
|
};
|
|
56
57
|
|
|
57
|
-
const checkArgs = (
|
|
58
|
+
const checkArgs = (names, push) => (path) => {
|
|
58
59
|
const fn = parseFn(path);
|
|
59
60
|
|
|
60
|
-
if (isArgExists(mainName, fn))
|
|
61
|
-
return false;
|
|
62
|
-
|
|
63
61
|
traverse(path, {
|
|
64
62
|
ReferencedIdentifier(path) {
|
|
65
|
-
|
|
63
|
+
const {name} = path.node;
|
|
64
|
+
|
|
65
|
+
if (!names.includes(name))
|
|
66
66
|
return;
|
|
67
67
|
|
|
68
|
-
if (isCallee(
|
|
68
|
+
if (isCallee(name, path))
|
|
69
69
|
return;
|
|
70
70
|
|
|
71
|
-
if (isArgExists(
|
|
71
|
+
if (isArgExists(name, fn))
|
|
72
72
|
return;
|
|
73
73
|
|
|
74
74
|
push({
|
|
75
75
|
path,
|
|
76
76
|
fn,
|
|
77
|
+
name,
|
|
77
78
|
});
|
|
78
79
|
},
|
|
79
|
-
[
|
|
80
|
+
[`__a(__args)`]: (currentPath) => {
|
|
81
|
+
const {callee} = currentPath.node;
|
|
82
|
+
const {name} = callee;
|
|
83
|
+
|
|
84
|
+
if (!names.includes(name))
|
|
85
|
+
return;
|
|
86
|
+
|
|
80
87
|
const bindings = currentPath.scope.getAllBindings();
|
|
81
88
|
|
|
82
|
-
if (bindings[
|
|
89
|
+
if (bindings[name])
|
|
83
90
|
return;
|
|
84
91
|
|
|
85
92
|
push({
|
|
86
93
|
path,
|
|
87
94
|
fn,
|
|
95
|
+
name,
|
|
88
96
|
});
|
|
89
97
|
},
|
|
90
98
|
});
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const addStore = require('./add-store');
|
|
4
|
-
const addPathStore = require('./add-path-store');
|
|
5
3
|
const applyProcessorsDestructuring = require('./apply-processors-destructuring');
|
|
6
4
|
const applyAsyncFormatter = require('./apply-async-formatter');
|
|
7
5
|
const applyCreateTest = require('./apply-create-test');
|
|
@@ -36,8 +34,8 @@ const renameOperateToOperator = require('./rename-operate-to-operator');
|
|
|
36
34
|
const replaceOperateWithOperator = require('./replace-operate-with-operator');
|
|
37
35
|
const shortenImports = require('./shorten-imports');
|
|
38
36
|
const declare = require('./declare');
|
|
39
|
-
const
|
|
40
|
-
const
|
|
37
|
+
const addTestArgs = require('./add-test-args');
|
|
38
|
+
const addTraverseArgs = require('./add-traverse-args');
|
|
41
39
|
const moveRequireOnTopLevel = require('./move-require-on-top-level');
|
|
42
40
|
const includer = require('./includer');
|
|
43
41
|
const createTest = require('./create-test');
|
|
@@ -53,8 +51,6 @@ const applyForOfToTrackFile = require('./apply-for-of-to-track-file');
|
|
|
53
51
|
const removeUnusedGetPropertiesArgument = require('./remove-unused-get-properties-argument');
|
|
54
52
|
|
|
55
53
|
module.exports.rules = {
|
|
56
|
-
'add-store': addStore,
|
|
57
|
-
'add-path-store': addPathStore,
|
|
58
54
|
'apply-processors-destructuring': applyProcessorsDestructuring,
|
|
59
55
|
'apply-async-formatter': applyAsyncFormatter,
|
|
60
56
|
'apply-create-test': applyCreateTest,
|
|
@@ -88,8 +84,8 @@ module.exports.rules = {
|
|
|
88
84
|
'replace-operate-with-operator': replaceOperateWithOperator,
|
|
89
85
|
'shorten-imports': shortenImports,
|
|
90
86
|
declare,
|
|
91
|
-
'add-args':
|
|
92
|
-
'add-
|
|
87
|
+
'add-test-args': addTestArgs,
|
|
88
|
+
'add-traverse-args': addTraverseArgs,
|
|
93
89
|
'move-require-on-top-level': moveRequireOnTopLevel,
|
|
94
90
|
includer,
|
|
95
91
|
'create-test': createTest,
|
package/package.json
CHANGED
package/lib/add-push/index.js
DELETED
package/lib/add-store/index.js
DELETED
|
File without changes
|