@putout/plugin-putout 28.5.1 → 28.7.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 +30 -0
- package/lib/convert-replace-to-traverse/index.js +26 -0
- package/lib/index.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,6 +62,7 @@ npm i @putout/plugin-putout -D
|
|
|
62
62
|
- ✅ [convert-plugins-element-to-tuple](#convert-plugins-element-to-tuple);
|
|
63
63
|
- ✅ [convert-push-object-to-push-path](#convert-push-object-to-push-path);
|
|
64
64
|
- ✅ [convert-replace-to-function](#convert-replace-to-function);
|
|
65
|
+
- ✅ [convert-replace-to-traverse](#convert-replace-to-traverse);
|
|
65
66
|
- ✅ [convert-replace-with](#convert-replace-with);
|
|
66
67
|
- ✅ [convert-replace-with-multiple](#convert-replace-with-multiple);
|
|
67
68
|
- ✅ [convert-report-to-function](#convert-report-to-function);
|
|
@@ -133,6 +134,7 @@ npm i @putout/plugin-putout -D
|
|
|
133
134
|
"putout/convert-replace-with": "on",
|
|
134
135
|
"putout/convert-replace-with-multiple": "on",
|
|
135
136
|
"putout/convert-replace-to-function": "on",
|
|
137
|
+
"putout/convert-replace-to-traverse": "on",
|
|
136
138
|
"putout/convert-match-to-function": "on",
|
|
137
139
|
"putout/convert-babel-types": "on",
|
|
138
140
|
"putout/convert-destructuring-to-identifier": "on",
|
|
@@ -943,6 +945,34 @@ module.exports.replace = () => ({
|
|
|
943
945
|
});
|
|
944
946
|
```
|
|
945
947
|
|
|
948
|
+
## convert-replace-to-traverse
|
|
949
|
+
|
|
950
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/a87ab50e500cd3aee3099063a48c0e3f/8dee3919638062563c9b39886d8bb8581f5722f2).
|
|
951
|
+
|
|
952
|
+
### ❌ Example of incorrect code
|
|
953
|
+
|
|
954
|
+
```js
|
|
955
|
+
export const fix = () => {};
|
|
956
|
+
export const replace = () => ({
|
|
957
|
+
[__json]: (path) => {
|
|
958
|
+
const __aPath = path.get('arguments.0');
|
|
959
|
+
const {importsPath} = getProperties(__aPath, ['imports']);
|
|
960
|
+
},
|
|
961
|
+
});
|
|
962
|
+
```
|
|
963
|
+
|
|
964
|
+
### ✅ Example of correct code
|
|
965
|
+
|
|
966
|
+
```js
|
|
967
|
+
export const fix = () => {};
|
|
968
|
+
export const traverse = () => ({
|
|
969
|
+
[__json]: (path) => {
|
|
970
|
+
const __aPath = path.get('arguments.0');
|
|
971
|
+
const {importsPath} = getProperties(__aPath, ['imports']);
|
|
972
|
+
},
|
|
973
|
+
});
|
|
974
|
+
```
|
|
975
|
+
|
|
946
976
|
## convert-match-to-function
|
|
947
977
|
|
|
948
978
|
### ❌ Example of incorrect code
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {operator} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {compare} = operator;
|
|
4
|
+
|
|
5
|
+
export const report = () => `Use 'traverse' instead of 'replace' when using 'fix'`;
|
|
6
|
+
|
|
7
|
+
export const match = () => ({
|
|
8
|
+
'export const replace = __a': contains('export const fix = __a'),
|
|
9
|
+
'module.exports.replace = __a': contains('module.exports.fix = __a'),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export const replace = () => ({
|
|
13
|
+
'export const replace = __a': 'export const traverse = __a',
|
|
14
|
+
'module.exports.replace = __a': 'module.exports.traverse = __a',
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const contains = (template) => (vars, path) => {
|
|
18
|
+
const {body} = path.scope.getProgramParent().path.node;
|
|
19
|
+
|
|
20
|
+
for (const current of body) {
|
|
21
|
+
if (compare(current, template))
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return false;
|
|
26
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as convertReplaceToTraverse from './convert-replace-to-traverse/index.js';
|
|
1
2
|
import * as applyEngineNodeVersion from './apply-engine-node-version/index.js';
|
|
2
3
|
import * as convertPushObjectToPushPath from './convert-push-object-to-push-path/index.js';
|
|
3
4
|
import * as applyTransformWithOptions from './apply-transform-with-options/index.js';
|
|
@@ -146,4 +147,5 @@ export const rules = {
|
|
|
146
147
|
'apply-transform-with-options': applyTransformWithOptions,
|
|
147
148
|
'convert-push-object-to-push-path': convertPushObjectToPushPath,
|
|
148
149
|
'apply-engine-node-version': applyEngineNodeVersion,
|
|
150
|
+
'convert-replace-to-traverse': convertReplaceToTraverse,
|
|
149
151
|
};
|
package/package.json
CHANGED