@putout/plugin-putout 29.31.0 → 29.32.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 +26 -2
- package/lib/apply-type-check/index.js +1 -1
- package/lib/convert-replacer-to-includer/index.js +61 -0
- package/lib/index.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -102,6 +102,7 @@ npm i @putout/plugin-putout -D
|
|
|
102
102
|
- ✅ [replace-test-message](#replace-test-message);
|
|
103
103
|
- ✅ [shorten-imports](#shorten-imports);
|
|
104
104
|
- ✅ [simplify-replace-template](#simplify-replace-template);
|
|
105
|
+
- ✅ [convert-replacer-to-includer](#convert-replacer-to-includer);
|
|
105
106
|
|
|
106
107
|
## File rules
|
|
107
108
|
|
|
@@ -151,7 +152,6 @@ npm i @putout/plugin-putout -D
|
|
|
151
152
|
"putout/apply-string-to-property-key": "on",
|
|
152
153
|
"putout/apply-transform-with-options": "on",
|
|
153
154
|
"putout/apply-traverser-to-ignore": "on",
|
|
154
|
-
|
|
155
155
|
"putout/apply-type-check": "on",
|
|
156
156
|
"putout/apply-vars": "on",
|
|
157
157
|
"putout/check-declare": "on",
|
|
@@ -201,7 +201,8 @@ npm i @putout/plugin-putout -D
|
|
|
201
201
|
"putout/replace-test-message": "on",
|
|
202
202
|
"putout/shorten-imports": "on",
|
|
203
203
|
"putout/simplify-replace-template": "on",
|
|
204
|
-
"putout/sort-readme-file": "on"
|
|
204
|
+
"putout/sort-readme-file": "on",
|
|
205
|
+
"putout/convert-replacer-to-includer": "on"
|
|
205
206
|
}
|
|
206
207
|
}
|
|
207
208
|
```
|
|
@@ -2275,6 +2276,29 @@ if (a.type === 'CallExpression') {}
|
|
|
2275
2276
|
if (isCallExpression(a)) {}
|
|
2276
2277
|
```
|
|
2277
2278
|
|
|
2279
|
+
## convert-replacer-to-includer
|
|
2280
|
+
|
|
2281
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/4b5e172466fda5e8fb114e767639f7ee/d3af95da4418b8c0e761d8cd50c1fa38a412b55c).
|
|
2282
|
+
|
|
2283
|
+
### ❌ Example of incorrect code
|
|
2284
|
+
|
|
2285
|
+
```js
|
|
2286
|
+
export const replace = () => ({
|
|
2287
|
+
'const [__a, {__b}] = __c(__d, __e)': 'const [__a, {__b}] = __c(__d, __e)',
|
|
2288
|
+
'const [__a, {__b = {}} = {}] = __c(__d, __e)': 'const [__a, {__b = {}} = {}] = __c(__d, __e)',
|
|
2289
|
+
});
|
|
2290
|
+
```
|
|
2291
|
+
|
|
2292
|
+
### ✅ Example of correct code
|
|
2293
|
+
|
|
2294
|
+
```js
|
|
2295
|
+
export const fix = () => {};
|
|
2296
|
+
export const include = () => [
|
|
2297
|
+
'const [__a, {__b}] = __c(__d, __e)',
|
|
2298
|
+
'const [__a, {__b = {}} = {}] = __c(__d, __e)',
|
|
2299
|
+
];
|
|
2300
|
+
```
|
|
2301
|
+
|
|
2278
2302
|
## License
|
|
2279
2303
|
|
|
2280
2304
|
MIT
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
template,
|
|
3
|
+
operator,
|
|
4
|
+
types,
|
|
5
|
+
} from 'putout';
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
compare,
|
|
9
|
+
insertBefore,
|
|
10
|
+
replaceWith,
|
|
11
|
+
} = operator;
|
|
12
|
+
|
|
13
|
+
const {
|
|
14
|
+
stringLiteral,
|
|
15
|
+
arrayExpression,
|
|
16
|
+
} = types;
|
|
17
|
+
|
|
18
|
+
const createInclude = template('export const include = () => LIST');
|
|
19
|
+
|
|
20
|
+
export const report = () => `Use 'Includer' instead of 'Replacer'`;
|
|
21
|
+
|
|
22
|
+
export const fix = ({path, properties}) => {
|
|
23
|
+
const list = [];
|
|
24
|
+
|
|
25
|
+
for (const property of properties) {
|
|
26
|
+
const {key} = property.node;
|
|
27
|
+
|
|
28
|
+
list.push(key.value);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
replaceWith(path, createInclude({
|
|
32
|
+
LIST: arrayExpression(list.map(stringLiteral)),
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
insertBefore(path, template.ast('export const fix = () => {}'));
|
|
36
|
+
};
|
|
37
|
+
export const traverse = ({push}) => ({
|
|
38
|
+
'export const replace = () => __object': (path) => {
|
|
39
|
+
const __objectPath = path.get('declaration.declarations.0.init.body');
|
|
40
|
+
const properties = __objectPath.get('properties');
|
|
41
|
+
|
|
42
|
+
for (const property of properties) {
|
|
43
|
+
const {
|
|
44
|
+
key,
|
|
45
|
+
value,
|
|
46
|
+
computed,
|
|
47
|
+
} = property.node;
|
|
48
|
+
|
|
49
|
+
if (computed)
|
|
50
|
+
return;
|
|
51
|
+
|
|
52
|
+
if (!compare(key, value))
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
push({
|
|
57
|
+
path,
|
|
58
|
+
properties,
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
});
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as convertReplacerToIncluder from './convert-replacer-to-includer/index.js';
|
|
1
2
|
import * as applyTypeCheck from './apply-type-check/index.js';
|
|
2
3
|
import * as sortReadmeFile from './sort-readme-file/index.js';
|
|
3
4
|
import * as applyStringToPropertyKey from './apply-string-to-property-key/index.js';
|
|
@@ -180,4 +181,5 @@ export const rules = {
|
|
|
180
181
|
'apply-string-to-property-key': applyStringToPropertyKey,
|
|
181
182
|
'sort-readme-file': sortReadmeFile,
|
|
182
183
|
'apply-type-check': applyTypeCheck,
|
|
184
|
+
'convert-replacer-to-includer': convertReplacerToIncluder,
|
|
183
185
|
};
|
package/package.json
CHANGED