@putout/plugin-putout 13.1.0 → 13.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 +25 -0
- package/lib/add-push/index.js +33 -16
- package/lib/apply-insert-before/index.js +7 -0
- package/lib/convert-replace-with/index.js +6 -2
- package/lib/convert-replace-with-multiple/index.js +7 -2
- package/lib/declare/operator.json +27 -0
- package/lib/index.js +1 -0
- package/package.json +1 -1
- package/lib/declare/operator.js +0 -27
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ npm i @putout/plugin-putout -D
|
|
|
21
21
|
"putout/apply-async-formatter": "on",
|
|
22
22
|
"putout/apply-declare": "on",
|
|
23
23
|
"putout/apply-remove": "on",
|
|
24
|
+
"putout/apply-insert-before": "on",
|
|
24
25
|
"putout/apply-insert-after": "on",
|
|
25
26
|
"putout/add-args": "on",
|
|
26
27
|
"putout/add-push": "on",
|
|
@@ -97,6 +98,30 @@ export const fix = (path) => {
|
|
|
97
98
|
};
|
|
98
99
|
```
|
|
99
100
|
|
|
101
|
+
## apply-insert-before
|
|
102
|
+
|
|
103
|
+
Better to use [`insertBefore(a, b)`](https://github.com/coderaiser/putout/tree/master/packages/operate#insert-before) method of `operator`.
|
|
104
|
+
|
|
105
|
+
### ❌ Example of incorrect code
|
|
106
|
+
|
|
107
|
+
```js
|
|
108
|
+
export const fix = (path) => {
|
|
109
|
+
path.insertBefore(path.get('init'));
|
|
110
|
+
};
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### ✅ Example of correct code
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
import {operator} from 'putout';
|
|
117
|
+
|
|
118
|
+
const {insertBefore} = operator;
|
|
119
|
+
|
|
120
|
+
export const fix = (path) => {
|
|
121
|
+
insertBefore(path, path.get('init'));
|
|
122
|
+
};
|
|
123
|
+
```
|
|
124
|
+
|
|
100
125
|
## apply-insert-after
|
|
101
126
|
|
|
102
127
|
Better to use [`insertAfter(a, b)`](https://github.com/coderaiser/putout/tree/master/packages/operate#insert-after) method of `operator`.
|
package/lib/add-push/index.js
CHANGED
|
@@ -12,27 +12,44 @@ const {
|
|
|
12
12
|
|
|
13
13
|
module.exports.report = () => `Add 'push' argument to 'traverse'`;
|
|
14
14
|
|
|
15
|
-
module.exports.fix = (
|
|
15
|
+
module.exports.fix = ({fn}) => {
|
|
16
16
|
const computed = false;
|
|
17
17
|
const shorthand = true;
|
|
18
18
|
const name = Identifier('push');
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
fn.params.push(ObjectPattern([
|
|
21
21
|
ObjectProperty(name, name, computed, shorthand),
|
|
22
22
|
]));
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
module.exports.traverse = ({push}) =>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
25
|
+
module.exports.traverse = ({push}) => {
|
|
26
|
+
const check = checkArgs(push);
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
'export const traverse = (__args) => __': check,
|
|
30
|
+
'module.exports.traverse = (__args) => __': check,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const checkArgs = (push) => (path) => {
|
|
35
|
+
const fn = parseFn(path);
|
|
36
|
+
|
|
37
|
+
if (fn.params.length)
|
|
38
|
+
return;
|
|
39
|
+
|
|
40
|
+
traverse(path, {
|
|
41
|
+
'push(__)': () => {
|
|
42
|
+
push({
|
|
43
|
+
path,
|
|
44
|
+
fn,
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
function parseFn(path) {
|
|
51
|
+
if (path.isAssignmentExpression())
|
|
52
|
+
return path.get('right').node;
|
|
53
|
+
|
|
54
|
+
return path.get('declaration.declarations.0.init').node;
|
|
55
|
+
}
|
|
@@ -9,7 +9,11 @@ const {
|
|
|
9
9
|
const fullstore = require('fullstore');
|
|
10
10
|
|
|
11
11
|
const {Identifier, ObjectProperty} = types;
|
|
12
|
-
const {
|
|
12
|
+
const {
|
|
13
|
+
replaceWith,
|
|
14
|
+
insertAfter,
|
|
15
|
+
insertBefore,
|
|
16
|
+
} = operator;
|
|
13
17
|
|
|
14
18
|
const isRecast = (program) => program.get('body.0.expression').isStringLiteral({
|
|
15
19
|
value: 'use strict',
|
|
@@ -42,7 +46,7 @@ module.exports.fix = ({path, calleePath, property, object, program, isInserted})
|
|
|
42
46
|
else if (types)
|
|
43
47
|
insertAfter(pathToInsert, replaceWithAST);
|
|
44
48
|
else
|
|
45
|
-
|
|
49
|
+
insertBefore(pathToInsert, replaceWithAST);
|
|
46
50
|
|
|
47
51
|
isInserted(true);
|
|
48
52
|
|
|
@@ -6,7 +6,12 @@ const {
|
|
|
6
6
|
types,
|
|
7
7
|
} = require('putout');
|
|
8
8
|
|
|
9
|
-
const {
|
|
9
|
+
const {
|
|
10
|
+
insertAfter,
|
|
11
|
+
replaceWith,
|
|
12
|
+
insertBefore,
|
|
13
|
+
} = operator;
|
|
14
|
+
|
|
10
15
|
const {Identifier, ObjectProperty} = types;
|
|
11
16
|
|
|
12
17
|
const isRecast = (program) => program.get('body.0').get('expression')
|
|
@@ -36,7 +41,7 @@ module.exports.fix = ({path, calleePath, property, object, program}) => {
|
|
|
36
41
|
if (isRecast(program))
|
|
37
42
|
return insertAfter(first, replaceWithAST);
|
|
38
43
|
|
|
39
|
-
return
|
|
44
|
+
return insertBefore(first, replaceWithAST);
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
const id = Identifier('replaceWithMultiple');
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"operator": "import {operator} from 'putout'",
|
|
3
|
+
"compare": "const {compare} = operator",
|
|
4
|
+
"compareAll": "const {compareAll} = operator",
|
|
5
|
+
"compareAny": "const {compareAny} = operator",
|
|
6
|
+
"compute": "const {compute} = operator",
|
|
7
|
+
"contains": "const {contains} = operator",
|
|
8
|
+
"declare": "const {declare} = operator",
|
|
9
|
+
"rename": "const {rename} = operator",
|
|
10
|
+
"renameProperty": "const {renameProperty} = operator",
|
|
11
|
+
"extract": "const {extract} = operator",
|
|
12
|
+
"getPathAfterImports": "const {getPathAfterImports} = operator",
|
|
13
|
+
"traverse": "const {traverse} = operator",
|
|
14
|
+
"isSimpleRegExp": "const {isSimpleRegExp} = operator",
|
|
15
|
+
"getTemplateValues": "const {getTemplateValues} = operator",
|
|
16
|
+
"addArgs": "const {addArgs} = operator",
|
|
17
|
+
"insertBefore": "const {insertBefore} = operator",
|
|
18
|
+
"insertAfter": "const {insertAfter} = operator",
|
|
19
|
+
"replaceWith": "const {replaceWith} = operator",
|
|
20
|
+
"replaceWithMultiple": "const {replaceWithMultiple} = operator",
|
|
21
|
+
"remove": "const {remove} = operator",
|
|
22
|
+
"isESM": "const {isESM} = operator",
|
|
23
|
+
"getProperty": "const {getProperty} = operator",
|
|
24
|
+
"getProperties": "const {getProperties} = operator",
|
|
25
|
+
"isSimple": "const {isSimple} = operator",
|
|
26
|
+
"setLiteralValue": "const {setLiteralValue} = operator"
|
|
27
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -9,6 +9,7 @@ module.exports.rules = {
|
|
|
9
9
|
...getRule('apply-async-formatter'),
|
|
10
10
|
...getRule('apply-create-test'),
|
|
11
11
|
...getRule('apply-remove'),
|
|
12
|
+
...getRule('apply-insert-before'),
|
|
12
13
|
...getRule('apply-insert-after'),
|
|
13
14
|
...getRule('apply-declare'),
|
|
14
15
|
...getRule('check-replace-code'),
|
package/package.json
CHANGED
package/lib/declare/operator.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
operator: `import {operator} from 'putout'`,
|
|
5
|
-
compare: `const {compare} = operator`,
|
|
6
|
-
compareAll: `const {compareAll} = operator`,
|
|
7
|
-
compareAny: `const {compareAny} = operator`,
|
|
8
|
-
compute: `const {compute} = operator`,
|
|
9
|
-
contains: `const {contains} = operator`,
|
|
10
|
-
declare: `const {declare} = operator`,
|
|
11
|
-
rename: `const {rename} = operator`,
|
|
12
|
-
renameProperty: `const {renameProperty} = operator`,
|
|
13
|
-
extract: `const {extract} = operator`,
|
|
14
|
-
getPathAfterImports: `const {getPathAfterImports} = operator`,
|
|
15
|
-
traverse: `const {traverse} = operator`,
|
|
16
|
-
isSimpleRegExp: `const {isSimpleRegExp} = operator`,
|
|
17
|
-
getTemplateValues: `const {getTemplateValues} = operator`,
|
|
18
|
-
addArgs: `const {addArgs} = operator`,
|
|
19
|
-
insertAfter: 'const {insertAfter} = operator',
|
|
20
|
-
replaceWith: `const {replaceWith} = operator`,
|
|
21
|
-
replaceWithMultiple: `const {replaceWithMultiple} = operator`,
|
|
22
|
-
remove: 'const {remove} = operator',
|
|
23
|
-
isESM: `const {isESM} = operator`,
|
|
24
|
-
getProperty: `const {getProperty} = operator`,
|
|
25
|
-
getProperties: `const {getProperties} = operator`,
|
|
26
|
-
isSimple: `const {isSimple} = operator`,
|
|
27
|
-
};
|