@putout/plugin-putout 19.3.1 → 19.5.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 +83 -5
- package/lib/add-arg.js +103 -0
- package/lib/add-push/index.js +2 -73
- package/lib/add-store/index.js +5 -0
- package/lib/index.js +2 -0
- package/lib/remove-unused-get-properties-argument/index.js +6 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,6 +13,59 @@ npm i @putout/plugin-putout -D
|
|
|
13
13
|
|
|
14
14
|
## Rules
|
|
15
15
|
|
|
16
|
+
- ✅ [add-args](#add-args);
|
|
17
|
+
- ✅ [add-await-to-progress](#add-await-to-progress);
|
|
18
|
+
- ✅ [add-index-to-import](#add-index-to-import);
|
|
19
|
+
- ✅ [add-push](#add-push);
|
|
20
|
+
- ✅ [add-store](#add-store);
|
|
21
|
+
- ✅ [add-track-file](#add-track-file);
|
|
22
|
+
- ✅ [apply-async-formatter](#apply-async-formatter);
|
|
23
|
+
- ✅ [apply-create-test](#apply-create-test);
|
|
24
|
+
- ✅ [apply-declare](#apply-declare);
|
|
25
|
+
- ✅ [apply-for-of-to-track-file](#apply-for-of-to-track-file);
|
|
26
|
+
- ✅ [apply-insert-after](#apply-insert-after);
|
|
27
|
+
- ✅ [apply-insert-before](#apply-insert-before);
|
|
28
|
+
- ✅ [apply-namespace-specifier](#apply-namespace-specifier);
|
|
29
|
+
- ✅ [apply-processors-destructuring](#apply-processors-destructuring);
|
|
30
|
+
- ✅ [apply-remove](#apply-remove);
|
|
31
|
+
- ✅ [apply-rename](#apply-rename);
|
|
32
|
+
- ✅ [apply-short-processors](#apply-short-processors);
|
|
33
|
+
- ✅ [check-match](#check-match);
|
|
34
|
+
- ✅ [check-replace-code](#check-replace-code);
|
|
35
|
+
- ✅ [convert-add-argument-to-add-args](#convert-add-argument-to-add-args);
|
|
36
|
+
- ✅ [convert-babel-types](#convert-babel-types);
|
|
37
|
+
- ✅ [convert-destructuring-to-identifier](#convert-destructuring-to-identifier);
|
|
38
|
+
- ✅ [convert-dirname-to-url](#convert-dirname-to-url);
|
|
39
|
+
- ✅ [convert-find-to-traverse](#convert-find-to-traverse);
|
|
40
|
+
- ✅ [convert-get-rule-to-require](#convert-get-rule-to-require);
|
|
41
|
+
- ✅ [convert-match-to-function](#convert-match-to-function);
|
|
42
|
+
- ✅ [convert-method-to-property](#convert-method-to-property);
|
|
43
|
+
- ✅ [convert-node-to-path-in-get-template-values](#convert-node-to-path-in-get-template-values);
|
|
44
|
+
- ✅ [convert-number-to-numeric](#convert-number-to-numeric);
|
|
45
|
+
- ✅ [convert-process-to-find](#convert-process-to-find);
|
|
46
|
+
- ✅ [convert-progress-to-track-file](#convert-progress-to-track-file);
|
|
47
|
+
- ✅ [convert-putout-test-to-create-test](#convert-putout-test-to-create-test);
|
|
48
|
+
- ✅ [convert-replace-to-function](#convert-replace-to-function);
|
|
49
|
+
- ✅ [convert-replace-with](#convert-replace-with);
|
|
50
|
+
- ✅ [convert-replace-with-multiple](#convert-replace-with-multiple);
|
|
51
|
+
- ✅ [convert-report-to-function](#convert-report-to-function);
|
|
52
|
+
- ✅ [convert-to-no-transform-code](#convert-to-no-transform-code);
|
|
53
|
+
- ✅ [convert-traverse-to-include](#convert-traverse-to-include);
|
|
54
|
+
- ✅ [convert-traverse-to-replace](#convert-traverse-to-replace);
|
|
55
|
+
- ✅ [convert-traverse-to-scan](#convert-traverse-to-scan);
|
|
56
|
+
- ✅ [convert-url-to-dirname](#convert-url-to-dirname);
|
|
57
|
+
- ✅ [create-test](#create-test);
|
|
58
|
+
- ✅ [declare](#declare);
|
|
59
|
+
- ✅ [includer](#includer);
|
|
60
|
+
- ✅ [move-require-on-top-level](#move-require-on-top-level);
|
|
61
|
+
- ✅ [remove-unused-get-properties-argument](#remove-unused-get-properties-argument);
|
|
62
|
+
- ✅ [rename-operate-to-operator](#rename-operate-to-operator);
|
|
63
|
+
- ✅ [replace-operate-with-operator](#replace-operate-with-operator);
|
|
64
|
+
- ✅ [replace-test-message](#replace-test-message);
|
|
65
|
+
- ✅ [shorten-imports](#shorten-imports);
|
|
66
|
+
|
|
67
|
+
## Config
|
|
68
|
+
|
|
16
69
|
```json
|
|
17
70
|
{
|
|
18
71
|
"rules": {
|
|
@@ -29,6 +82,7 @@ npm i @putout/plugin-putout -D
|
|
|
29
82
|
"putout/apply-for-of-to-track-file": "on",
|
|
30
83
|
"putout/add-args": "on",
|
|
31
84
|
"putout/add-push": "on",
|
|
85
|
+
"putout/add-store": "on",
|
|
32
86
|
"putout/add-track-file": "on",
|
|
33
87
|
"putout/add-await-to-progress": "on",
|
|
34
88
|
"putout/add-index-to-import": "on",
|
|
@@ -781,6 +835,34 @@ module.exports.traverse = ({push}) => ({
|
|
|
781
835
|
});
|
|
782
836
|
```
|
|
783
837
|
|
|
838
|
+
## add-store
|
|
839
|
+
|
|
840
|
+
### ❌ Example of incorrect code
|
|
841
|
+
|
|
842
|
+
```js
|
|
843
|
+
module.exports.traverse = () => ({
|
|
844
|
+
ImportDeclaration(path) {
|
|
845
|
+
const {node} = path;
|
|
846
|
+
const {name} = node.specifiers[0].local;
|
|
847
|
+
|
|
848
|
+
store('name', name);
|
|
849
|
+
},
|
|
850
|
+
});
|
|
851
|
+
```
|
|
852
|
+
|
|
853
|
+
### ✅ Example of correct code
|
|
854
|
+
|
|
855
|
+
```js
|
|
856
|
+
module.exports.traverse = ({store}) => ({
|
|
857
|
+
ImportDeclaration(path) {
|
|
858
|
+
const {node} = path;
|
|
859
|
+
const {name} = node.specifiers[0].local;
|
|
860
|
+
|
|
861
|
+
store('name', name);
|
|
862
|
+
},
|
|
863
|
+
});
|
|
864
|
+
```
|
|
865
|
+
|
|
784
866
|
## add-await-to-progress
|
|
785
867
|
|
|
786
868
|
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/978d70945edfa369390ea059654ff04d/89225c04039b9c0e9057aad34852c9428264f119).
|
|
@@ -1130,11 +1212,7 @@ const {
|
|
|
1130
1212
|
overridesPath,
|
|
1131
1213
|
parserPath,
|
|
1132
1214
|
rulesPath,
|
|
1133
|
-
} = getProperties(__jsonPath, [
|
|
1134
|
-
'parser',
|
|
1135
|
-
'rules',
|
|
1136
|
-
'extends',
|
|
1137
|
-
]);
|
|
1215
|
+
} = getProperties(__jsonPath, ['parser', 'rules', 'extends']);
|
|
1138
1216
|
```
|
|
1139
1217
|
|
|
1140
1218
|
## License
|
package/lib/add-arg.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types, operator} = require('putout');
|
|
4
|
+
const {traverse} = operator;
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
ObjectProperty,
|
|
8
|
+
ObjectPattern,
|
|
9
|
+
Identifier,
|
|
10
|
+
} = types;
|
|
11
|
+
|
|
12
|
+
module.exports = function addArg(name) {
|
|
13
|
+
return {
|
|
14
|
+
report: createReport(name),
|
|
15
|
+
fix: createFix(name),
|
|
16
|
+
traverse: createTraverse(name),
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const createReport = (name) => () => `Add '${name}' argument to 'traverse'`;
|
|
21
|
+
|
|
22
|
+
const createFix = (mainName) => ({fn}) => {
|
|
23
|
+
const computed = false;
|
|
24
|
+
const shorthand = true;
|
|
25
|
+
const name = Identifier(mainName);
|
|
26
|
+
const property = ObjectProperty(name, name, computed, shorthand);
|
|
27
|
+
|
|
28
|
+
if (!fn.params.length) {
|
|
29
|
+
fn.params.push(ObjectPattern([property]));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
fn.params[0].properties.push(property);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const createTraverse = (name) => ({push}) => {
|
|
37
|
+
const check = checkArgs(name, push);
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
'export const traverse = (__args) => __': check,
|
|
41
|
+
'module.exports.traverse = (__args) => __': check,
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const isArgExists = (mainName, fn) => {
|
|
46
|
+
if (!fn.params.length)
|
|
47
|
+
return false;
|
|
48
|
+
|
|
49
|
+
for (const prop of fn.params[0].properties) {
|
|
50
|
+
if (prop.key.name === mainName)
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return false;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const checkArgs = (mainName, push) => (path) => {
|
|
58
|
+
const fn = parseFn(path);
|
|
59
|
+
|
|
60
|
+
if (isArgExists(mainName, fn))
|
|
61
|
+
return false;
|
|
62
|
+
|
|
63
|
+
traverse(path, {
|
|
64
|
+
ReferencedIdentifier(path) {
|
|
65
|
+
if (path.node.name !== mainName)
|
|
66
|
+
return;
|
|
67
|
+
|
|
68
|
+
if (isCallee(mainName, path))
|
|
69
|
+
return;
|
|
70
|
+
|
|
71
|
+
push({
|
|
72
|
+
path,
|
|
73
|
+
fn,
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
[`${mainName}(__args)`]: (currentPath) => {
|
|
77
|
+
const bindings = currentPath.scope.getAllBindings();
|
|
78
|
+
|
|
79
|
+
if (bindings[mainName])
|
|
80
|
+
return;
|
|
81
|
+
|
|
82
|
+
push({
|
|
83
|
+
path,
|
|
84
|
+
fn,
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
function parseFn(path) {
|
|
91
|
+
if (path.isAssignmentExpression())
|
|
92
|
+
return path.get('right').node;
|
|
93
|
+
|
|
94
|
+
return path.get('declaration.declarations.0.init').node;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function isCallee(name, {parentPath}) {
|
|
98
|
+
return parentPath
|
|
99
|
+
.get('callee')
|
|
100
|
+
.isIdentifier({
|
|
101
|
+
name,
|
|
102
|
+
});
|
|
103
|
+
}
|
package/lib/add-push/index.js
CHANGED
|
@@ -1,76 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const {traverse} = operator;
|
|
5
|
-
const {
|
|
6
|
-
ObjectProperty,
|
|
7
|
-
ObjectPattern,
|
|
8
|
-
Identifier,
|
|
9
|
-
} = types;
|
|
3
|
+
const addArg = require('../add-arg.js');
|
|
10
4
|
|
|
11
|
-
module.exports
|
|
12
|
-
|
|
13
|
-
module.exports.fix = ({fn}) => {
|
|
14
|
-
const computed = false;
|
|
15
|
-
const shorthand = true;
|
|
16
|
-
const name = Identifier('push');
|
|
17
|
-
|
|
18
|
-
fn.params.push(ObjectPattern([
|
|
19
|
-
ObjectProperty(name, name, computed, shorthand),
|
|
20
|
-
]));
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
module.exports.traverse = ({push}) => {
|
|
24
|
-
const check = checkArgs(push);
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
'export const traverse = (__args) => __': check,
|
|
28
|
-
'module.exports.traverse = (__args) => __': check,
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const checkArgs = (push) => (path) => {
|
|
33
|
-
const fn = parseFn(path);
|
|
34
|
-
|
|
35
|
-
if (fn.params.length)
|
|
36
|
-
return;
|
|
37
|
-
|
|
38
|
-
traverse(path, {
|
|
39
|
-
ReferencedIdentifier(path) {
|
|
40
|
-
if (path.node.name !== 'push')
|
|
41
|
-
return;
|
|
42
|
-
|
|
43
|
-
if (isCalleePush(path))
|
|
44
|
-
return;
|
|
45
|
-
|
|
46
|
-
push({
|
|
47
|
-
path,
|
|
48
|
-
fn,
|
|
49
|
-
});
|
|
50
|
-
},
|
|
51
|
-
'push(__)': (currentPath) => {
|
|
52
|
-
if (currentPath.scope.getAllBindings().push)
|
|
53
|
-
return;
|
|
54
|
-
|
|
55
|
-
push({
|
|
56
|
-
path,
|
|
57
|
-
fn,
|
|
58
|
-
});
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
function parseFn(path) {
|
|
64
|
-
if (path.isAssignmentExpression())
|
|
65
|
-
return path.get('right').node;
|
|
66
|
-
|
|
67
|
-
return path.get('declaration.declarations.0.init').node;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function isCalleePush({parentPath}) {
|
|
71
|
-
return parentPath
|
|
72
|
-
.get('callee')
|
|
73
|
-
.isIdentifier({
|
|
74
|
-
name: 'push',
|
|
75
|
-
});
|
|
76
|
-
}
|
|
5
|
+
module.exports = addArg('push');
|
package/lib/index.js
CHANGED
|
@@ -49,6 +49,7 @@ const convertProgressToTrackFile = require('./convert-progress-to-track-file');
|
|
|
49
49
|
const addAwaitToProgress = require('./add-await-to-progress');
|
|
50
50
|
const applyForOfToTrackFile = require('./apply-for-of-to-track-file');
|
|
51
51
|
const removeUnusedGetPropertiesArgument = require('./remove-unused-get-properties-argument');
|
|
52
|
+
const addStore = require('./add-store');
|
|
52
53
|
|
|
53
54
|
module.exports.rules = {
|
|
54
55
|
'apply-processors-destructuring': applyProcessorsDestructuring,
|
|
@@ -100,4 +101,5 @@ module.exports.rules = {
|
|
|
100
101
|
'add-await-to-progress': addAwaitToProgress,
|
|
101
102
|
'apply-for-of-to-track-file': applyForOfToTrackFile,
|
|
102
103
|
'remove-unused-get-properties-argument': removeUnusedGetPropertiesArgument,
|
|
104
|
+
'add-store': addStore,
|
|
103
105
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {operator} = require('putout');
|
|
3
|
+
const {operator, types} = require('putout');
|
|
4
|
+
const {isObjectPattern} = types;
|
|
4
5
|
const {
|
|
5
6
|
getTemplateValues,
|
|
6
7
|
remove,
|
|
@@ -17,6 +18,10 @@ module.exports.fix = ({path}) => {
|
|
|
17
18
|
module.exports.traverse = ({push}) => ({
|
|
18
19
|
[GET_PROPERTIES]: (path) => {
|
|
19
20
|
const {__a} = getTemplateValues(path, GET_PROPERTIES);
|
|
21
|
+
|
|
22
|
+
if (!isObjectPattern(__a))
|
|
23
|
+
return;
|
|
24
|
+
|
|
20
25
|
const __cPath = path.get('declarations.0.init.arguments.1');
|
|
21
26
|
|
|
22
27
|
for (const nameProp of __cPath.get('elements')) {
|
package/package.json
CHANGED