@putout/plugin-putout 29.19.0 → 29.20.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 +29 -0
- package/lib/check-match/index.js +2 -2
- package/lib/convert-push-object-to-push-path/index.js +3 -3
- package/lib/convert-traverse-to-replace/index.js +2 -2
- package/lib/convert-traverse-to-super-traverse/index.js +25 -0
- package/lib/declare/operator/index.js +1 -0
- package/lib/index.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -79,6 +79,7 @@ npm i @putout/plugin-putout -D
|
|
|
79
79
|
- ✅ [convert-to-no-transform-code](#convert-to-no-transform-code);
|
|
80
80
|
- ✅ [convert-include-to-traverse](#convert-include-to-traverse);
|
|
81
81
|
- ✅ [convert-traverse-to-include](#convert-traverse-to-include);
|
|
82
|
+
- ✅ [convert-traverse-to-super-traverse](#convert-traverse-to-super-traverse);
|
|
82
83
|
- ✅ [convert-traverse-to-replace](#convert-traverse-to-replace);
|
|
83
84
|
- ✅ [convert-traverse-to-scan](#convert-traverse-to-scan);
|
|
84
85
|
- ✅ [convert-url-to-dirname](#convert-url-to-dirname);
|
|
@@ -164,6 +165,7 @@ npm i @putout/plugin-putout -D
|
|
|
164
165
|
"putout/convert-traverse-to-include": "on",
|
|
165
166
|
"putout/convert-traverse-to-replace": "on",
|
|
166
167
|
"putout/convert-traverse-to-scan": "on",
|
|
168
|
+
"putout/convert-traverse-to-super-traverse": "on",
|
|
167
169
|
"putout/convert-process-to-find": "on",
|
|
168
170
|
"putout/convert-method-to-property": "on",
|
|
169
171
|
"putout/convert-add-argument-to-add-args": "on",
|
|
@@ -1227,6 +1229,32 @@ module.exports.include = () => [
|
|
|
1227
1229
|
];
|
|
1228
1230
|
```
|
|
1229
1231
|
|
|
1232
|
+
## convert-traverse-to-super-traverse
|
|
1233
|
+
|
|
1234
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/131b7af8e25a454b293d592d2faa2cd8/f8ae176880de753eb50236d841a1a3bb8e494e2f).
|
|
1235
|
+
|
|
1236
|
+
### ❌ Example of incorrect code
|
|
1237
|
+
|
|
1238
|
+
```js
|
|
1239
|
+
export const traverse = () => ({
|
|
1240
|
+
[__markdown]: (path) => {
|
|
1241
|
+
traverse();
|
|
1242
|
+
},
|
|
1243
|
+
});
|
|
1244
|
+
```
|
|
1245
|
+
|
|
1246
|
+
### ✅ Example of correct code
|
|
1247
|
+
|
|
1248
|
+
```js
|
|
1249
|
+
export const traverse = () => ({
|
|
1250
|
+
[__markdown]: (path) => {
|
|
1251
|
+
superTraverse(path, {
|
|
1252
|
+
'__a(__b, __c)': (path) => {},
|
|
1253
|
+
});
|
|
1254
|
+
},
|
|
1255
|
+
});
|
|
1256
|
+
```
|
|
1257
|
+
|
|
1230
1258
|
## convert-traverse-to-replace
|
|
1231
1259
|
|
|
1232
1260
|
### ❌ Example of incorrect code
|
|
@@ -2135,6 +2163,7 @@ test('github: set-message-of-commit-fixes: no report after transform', (t) => {
|
|
|
2135
2163
|
## remove-useless-printer-option
|
|
2136
2164
|
|
|
2137
2165
|
Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/f176313cf67fd6d7138470385511319f/5b26aa45db21f250016d228b7bbabbb3c10b582b).
|
|
2166
|
+
|
|
2138
2167
|
`putout` printer used by default, so there is no need to pass it.
|
|
2139
2168
|
|
|
2140
2169
|
### ❌ Example of incorrect code
|
package/lib/check-match/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import {operator, types} from 'putout';
|
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
4
|
getTemplateValues,
|
|
5
|
-
|
|
5
|
+
superTraverse,
|
|
6
6
|
} = operator;
|
|
7
7
|
|
|
8
8
|
const {isStringLiteral} = types;
|
|
@@ -22,7 +22,7 @@ export const match = () => ({
|
|
|
22
22
|
const namesMatch = getNames(__object);
|
|
23
23
|
const namesReplace = [];
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
superTraverse(path.parentPath.parentPath, {
|
|
26
26
|
[PATTERN_REPLACE_RETURN]: (path) => {
|
|
27
27
|
const {__body} = getTemplateValues(path, PATTERN_REPLACE_RETURN);
|
|
28
28
|
const object = __body.body.at(-1).argument;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {operator} from 'putout';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {superTraverse} = operator;
|
|
4
4
|
|
|
5
5
|
export const report = () => `Use 'push(__a)' instead of 'push({path: __a})'`;
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@ export const match = () => ({
|
|
|
9
9
|
let is = false;
|
|
10
10
|
const programPath = path.scope.getProgramParent().path;
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
superTraverse(programPath, {
|
|
13
13
|
'export const fix = (path) => __body': () => {
|
|
14
14
|
is = true;
|
|
15
15
|
},
|
|
@@ -20,7 +20,7 @@ export const match = () => ({
|
|
|
20
20
|
'export const fix = ({path}) => __a': (vars, {parentPath}) => {
|
|
21
21
|
let is = false;
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
superTraverse(parentPath, {
|
|
24
24
|
'push({path: __a})': () => {
|
|
25
25
|
is = true;
|
|
26
26
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {operator} from 'putout';
|
|
2
2
|
|
|
3
|
-
const {contains,
|
|
3
|
+
const {contains, superTraverse} = operator;
|
|
4
4
|
|
|
5
5
|
export const report = () => 'Replacer should be used instead of Traverser (https://git.io/JqcMn)';
|
|
6
6
|
|
|
@@ -38,7 +38,7 @@ function check(path) {
|
|
|
38
38
|
let hasPushCall = false;
|
|
39
39
|
let hasTraverseMethod = false;
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
superTraverse(path, {
|
|
42
42
|
'ObjectMethod|ObjectProperty': (path) => {
|
|
43
43
|
const keyPath = path.get('key');
|
|
44
44
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {operator, types} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {isIdentifier} = types;
|
|
4
|
+
|
|
5
|
+
const {getBindingPath} = operator;
|
|
6
|
+
|
|
7
|
+
export const report = () => `Use 'superTraverse' instead of 'traverse'`;
|
|
8
|
+
|
|
9
|
+
export const match = () => ({
|
|
10
|
+
'traverse(__a, __b)': (vars, path) => {
|
|
11
|
+
const bindingPath = getBindingPath(path, 'traverse');
|
|
12
|
+
|
|
13
|
+
if (!bindingPath)
|
|
14
|
+
return true;
|
|
15
|
+
|
|
16
|
+
if (!isIdentifier(bindingPath.node.init))
|
|
17
|
+
return false;
|
|
18
|
+
|
|
19
|
+
return bindingPath.node.init.name === 'operator';
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export const replace = () => ({
|
|
24
|
+
'traverse(__a, __b)': 'superTraverse(__a, __b)',
|
|
25
|
+
});
|
|
@@ -33,6 +33,7 @@ export default {
|
|
|
33
33
|
getBinding: 'const {getBinding} = operator',
|
|
34
34
|
getBindingPath: 'const {getBindingPath} = operator',
|
|
35
35
|
traverse: 'const {traverse} = operator',
|
|
36
|
+
superTraverse: 'const {superTraverse} = operator',
|
|
36
37
|
getTemplateValues: 'const {getTemplateValues} = operator',
|
|
37
38
|
addArgs: 'const {addArgs} = operator',
|
|
38
39
|
insertBefore: 'const {insertBefore} = operator',
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as convertTraverseToSuperTraverse from './convert-traverse-to-super-traverse/index.js';
|
|
1
2
|
import * as applyDestructuringToOptions from './apply-destructuring-to-options/index.js';
|
|
2
3
|
import * as applyGetBinding from './apply-get-binding/index.js';
|
|
3
4
|
import * as applyNameToIsIdentifier from './apply-name-to-is-identifier/index.js';
|
|
@@ -172,4 +173,5 @@ export const rules = {
|
|
|
172
173
|
'apply-name-to-is-identifier': applyNameToIsIdentifier,
|
|
173
174
|
'apply-get-binding': applyGetBinding,
|
|
174
175
|
'apply-destructuring-to-options': applyDestructuringToOptions,
|
|
176
|
+
'convert-traverse-to-super-traverse': convertTraverseToSuperTraverse,
|
|
175
177
|
};
|
package/package.json
CHANGED