@putout/plugin-putout 13.0.0 → 13.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 +53 -2
- package/lib/apply-insert-after/index.js +7 -0
- package/lib/apply-insert-before/index.js +7 -0
- package/lib/apply-remove/index.js +1 -1
- package/lib/convert-replace-with/index.js +6 -2
- package/lib/convert-replace-with-multiple/index.js +7 -2
- package/lib/convert-traverse-to-include/index.js +2 -2
- package/lib/declare/operator.json +27 -0
- package/lib/index.js +2 -0
- package/package.json +2 -2
- package/lib/declare/operator.js +0 -26
package/README.md
CHANGED
|
@@ -19,8 +19,10 @@ npm i @putout/plugin-putout -D
|
|
|
19
19
|
"putout/apply-create-test": "on",
|
|
20
20
|
"putout/apply-processors-destructuring": "on",
|
|
21
21
|
"putout/apply-async-formatter": "on",
|
|
22
|
-
"putout/apply-remove": "on",
|
|
23
22
|
"putout/apply-declare": "on",
|
|
23
|
+
"putout/apply-remove": "on",
|
|
24
|
+
"putout/apply-insert-before": "on",
|
|
25
|
+
"putout/apply-insert-after": "on",
|
|
24
26
|
"putout/add-args": "on",
|
|
25
27
|
"putout/add-push": "on",
|
|
26
28
|
"putout/check-match": "on",
|
|
@@ -96,6 +98,55 @@ export const fix = (path) => {
|
|
|
96
98
|
};
|
|
97
99
|
```
|
|
98
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
|
+
|
|
125
|
+
## apply-insert-after
|
|
126
|
+
|
|
127
|
+
Better to use [`insertAfter(a, b)`](https://github.com/coderaiser/putout/tree/master/packages/operate#insert-after) method of `operator`.
|
|
128
|
+
It helps to avoid duplication of comments.
|
|
129
|
+
|
|
130
|
+
### ❌ Example of incorrect code
|
|
131
|
+
|
|
132
|
+
```js
|
|
133
|
+
export const fix = (path) => {
|
|
134
|
+
path.insertAfter(path.get('init'));
|
|
135
|
+
};
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### ✅ Example of correct code
|
|
139
|
+
|
|
140
|
+
```js
|
|
141
|
+
import {operator} from 'putout';
|
|
142
|
+
|
|
143
|
+
const {insertAfter} = operator;
|
|
144
|
+
|
|
145
|
+
export const fix = (path) => {
|
|
146
|
+
insertAfter(path, path.get('init'));
|
|
147
|
+
};
|
|
148
|
+
```
|
|
149
|
+
|
|
99
150
|
## apply-declare
|
|
100
151
|
|
|
101
152
|
Better to use [`Declareator`](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#declarator) instead of `operator.declare()`.
|
|
@@ -218,7 +269,7 @@ isNumericLiteral(node);
|
|
|
218
269
|
|
|
219
270
|
## convert-putout-test-to-create-test
|
|
220
271
|
|
|
221
|
-
Fixes results of [@putout/convert-commonjs-to-esm](https://github.com/coderaiser/putout/tree/master/packages/plugin-convert-commonjs-to-esm) work.
|
|
272
|
+
Fixes results of [@putout/convert-commonjs-to-esm](https://github.com/coderaiser/putout/tree/master/packages/plugin-convert-commonjs-to-esm#readme) work.
|
|
222
273
|
|
|
223
274
|
### ❌ Example of incorrect code
|
|
224
275
|
|
|
@@ -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');
|
|
@@ -7,7 +7,7 @@ const {
|
|
|
7
7
|
} = require('putout');
|
|
8
8
|
|
|
9
9
|
const {StringLiteral} = types;
|
|
10
|
-
const {compare} = operator;
|
|
10
|
+
const {compare, remove} = operator;
|
|
11
11
|
|
|
12
12
|
const isPush = (path) => path.get('value').isIdentifier({
|
|
13
13
|
name: 'push',
|
|
@@ -42,7 +42,7 @@ module.exports.replace = () => ({
|
|
|
42
42
|
|
|
43
43
|
if (isPush(propertyPath) || isBlock(propertyPath)) {
|
|
44
44
|
node.right.body.elements.push(StringLiteral(name));
|
|
45
|
-
|
|
45
|
+
remove(propertyPath);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -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,8 @@ 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'),
|
|
13
|
+
...getRule('apply-insert-after'),
|
|
12
14
|
...getRule('apply-declare'),
|
|
13
15
|
...getRule('check-replace-code'),
|
|
14
16
|
...getRule('check-match'),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-putout",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.2.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout plugin helps with plugins development",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"lerna": "^6.0.1",
|
|
45
45
|
"madrun": "^9.0.0",
|
|
46
46
|
"montag": "^1.2.1",
|
|
47
|
-
"nodemon": "^
|
|
47
|
+
"nodemon": "^3.0.1"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"putout": ">=30"
|
package/lib/declare/operator.js
DELETED
|
@@ -1,26 +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
|
-
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
|
-
};
|