@putout/plugin-putout 20.0.0 → 20.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
CHANGED
|
@@ -62,6 +62,7 @@ npm i @putout/plugin-putout -D
|
|
|
62
62
|
- ✅ [replace-operate-with-operator](#replace-operate-with-operator);
|
|
63
63
|
- ✅ [replace-test-message](#replace-test-message);
|
|
64
64
|
- ✅ [shorten-imports](#shorten-imports);
|
|
65
|
+
- ✅ [simplify-replace-template](#simplify-replace-template);
|
|
65
66
|
|
|
66
67
|
## Config
|
|
67
68
|
|
|
@@ -113,7 +114,8 @@ npm i @putout/plugin-putout -D
|
|
|
113
114
|
"putout/includer": "on",
|
|
114
115
|
"putout/move-require-on-top-level": "on",
|
|
115
116
|
"putout/replace-test-message": "on",
|
|
116
|
-
"putout/remove-unused-get-properties-argument": "on"
|
|
117
|
+
"putout/remove-unused-get-properties-argument": "on",
|
|
118
|
+
"putout/simplify-replace-template": "on"
|
|
117
119
|
}
|
|
118
120
|
}
|
|
119
121
|
```
|
|
@@ -838,7 +840,7 @@ module.exports.traverse = ({push}) => ({
|
|
|
838
840
|
});
|
|
839
841
|
```
|
|
840
842
|
|
|
841
|
-
- `store`
|
|
843
|
+
- [`store`](https://github.com/coderaiser/putout/blob/master/packages/engine-runner/README.md#store)
|
|
842
844
|
|
|
843
845
|
### ❌ Example of incorrect code
|
|
844
846
|
|
|
@@ -866,7 +868,7 @@ module.exports.traverse = ({store}) => ({
|
|
|
866
868
|
});
|
|
867
869
|
```
|
|
868
870
|
|
|
869
|
-
- `pathStore
|
|
871
|
+
- [`pathStore`](https://github.com/coderaiser/putout/blob/master/packages/engine-runner/README.md#pathstore)
|
|
870
872
|
|
|
871
873
|
### ❌ Example of incorrect code
|
|
872
874
|
|
|
@@ -1236,6 +1238,24 @@ const {
|
|
|
1236
1238
|
} = getProperties(__jsonPath, ['parser', 'rules', 'extends']);
|
|
1237
1239
|
```
|
|
1238
1240
|
|
|
1241
|
+
## simplify-replace-template
|
|
1242
|
+
|
|
1243
|
+
### ❌ Example of incorrect code
|
|
1244
|
+
|
|
1245
|
+
```js
|
|
1246
|
+
module.exports.replace = () => ({
|
|
1247
|
+
'if (__a) {__b} else {__c}': () => 'if (__a) __b; else __c',
|
|
1248
|
+
});
|
|
1249
|
+
```
|
|
1250
|
+
|
|
1251
|
+
### ✅ Example of correct code
|
|
1252
|
+
|
|
1253
|
+
```js
|
|
1254
|
+
module.exports.replace = () => ({
|
|
1255
|
+
'if (__a) {__b} else {__c}': 'if (__a) __b; else __c',
|
|
1256
|
+
});
|
|
1257
|
+
```
|
|
1258
|
+
|
|
1239
1259
|
## License
|
|
1240
1260
|
|
|
1241
1261
|
MIT
|
|
@@ -11,6 +11,7 @@ const {
|
|
|
11
11
|
replaceWith,
|
|
12
12
|
insertBefore,
|
|
13
13
|
compare,
|
|
14
|
+
getPathAfterRequires,
|
|
14
15
|
} = operator;
|
|
15
16
|
|
|
16
17
|
const {
|
|
@@ -65,16 +66,6 @@ module.exports.replace = () => ({
|
|
|
65
66
|
},
|
|
66
67
|
});
|
|
67
68
|
|
|
68
|
-
function getLatest(body) {
|
|
69
|
-
let path;
|
|
70
|
-
|
|
71
|
-
for (path of body)
|
|
72
|
-
if (!compare(path, REQUIRE))
|
|
73
|
-
break;
|
|
74
|
-
|
|
75
|
-
return path;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
69
|
function addRequire({__a, id, path}) {
|
|
79
70
|
const programPath = path.scope.getProgramParent().path;
|
|
80
71
|
const body = programPath.get('body');
|
|
@@ -86,7 +77,7 @@ function addRequire({__a, id, path}) {
|
|
|
86
77
|
});
|
|
87
78
|
|
|
88
79
|
if (compare(first, REQUIRE)) {
|
|
89
|
-
const latest =
|
|
80
|
+
const latest = getPathAfterRequires(body.slice(1));
|
|
90
81
|
insertBefore(latest, nodeRequire);
|
|
91
82
|
|
|
92
83
|
return path;
|
|
@@ -17,6 +17,7 @@ module.exports = {
|
|
|
17
17
|
renameProperty: 'const {renameProperty} = operator',
|
|
18
18
|
extract: 'const {extract} = operator',
|
|
19
19
|
getPathAfterImports: 'const {getPathAfterImports} = operator',
|
|
20
|
+
getPathAfterRequires: 'const {getPathAfterRequires} = operator',
|
|
20
21
|
getBinding: 'const {getBinding} = operator',
|
|
21
22
|
getBindingPath: 'const {getBindingPath} = operator',
|
|
22
23
|
traverse: 'const {traverse} = operator',
|
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 simplifyReplaceTemplate = require('./simplify-replace-template');
|
|
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
|
+
'simplify-replace-template': simplifyReplaceTemplate,
|
|
103
105
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {operator} = require('putout');
|
|
4
|
+
const {compareAny, replaceWith} = operator;
|
|
5
|
+
|
|
6
|
+
const parentNodesList = [
|
|
7
|
+
'module.exports.replace = __',
|
|
8
|
+
'export const replace = __',
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
module.exports.report = () => `Simplify replce template`;
|
|
12
|
+
|
|
13
|
+
module.exports.fix = (path) => {
|
|
14
|
+
const {body} = path.node;
|
|
15
|
+
replaceWith(path, body);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
module.exports.include = () => [
|
|
19
|
+
'() => "__a"',
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
module.exports.filter = (path) => {
|
|
23
|
+
return path.find(isReplace);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function isReplace(path) {
|
|
27
|
+
return compareAny(path, parentNodesList);
|
|
28
|
+
}
|
package/package.json
CHANGED