@putout/plugin-putout 22.3.0 → 22.5.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 +38 -0
- package/lib/apply-fixture-name-to-message/index.js +19 -9
- package/lib/apply-vars/index.js +7 -0
- package/lib/index.js +2 -0
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -28,6 +28,7 @@ npm i @putout/plugin-putout -D
|
|
|
28
28
|
- ✅ [apply-fixture-name-to-message](#apply-fixture-name-to-message);
|
|
29
29
|
- ✅ [apply-insert-after](#apply-insert-after);
|
|
30
30
|
- ✅ [apply-insert-before](#apply-insert-before);
|
|
31
|
+
- ✅ [apply-vars](#apply-vars);
|
|
31
32
|
- ✅ [apply-namespace-specifier](#apply-namespace-specifier);
|
|
32
33
|
- ✅ [apply-processors-destructuring](#apply-processors-destructuring);
|
|
33
34
|
- ✅ [apply-remove](#apply-remove);
|
|
@@ -92,6 +93,7 @@ npm i @putout/plugin-putout -D
|
|
|
92
93
|
"putout/apply-remove": "on",
|
|
93
94
|
"putout/apply-insert-before": "on",
|
|
94
95
|
"putout/apply-insert-after": "on",
|
|
96
|
+
"putout/apply-vars": "on",
|
|
95
97
|
"putout/apply-short-processors": "on",
|
|
96
98
|
"putout/apply-namespace-specifier": "on",
|
|
97
99
|
"putout/apply-for-of-to-track-file": "on",
|
|
@@ -283,6 +285,42 @@ export const fix = (path) => {
|
|
|
283
285
|
};
|
|
284
286
|
```
|
|
285
287
|
|
|
288
|
+
## apply-vars
|
|
289
|
+
|
|
290
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/f96aaef6c54049ca91497a17f7a4b88a/b960916e73a7f51c1c0425ad9a3f304452c0d159).
|
|
291
|
+
|
|
292
|
+
### ❌ Example of incorrect code
|
|
293
|
+
|
|
294
|
+
```js
|
|
295
|
+
export const replace = () => ({
|
|
296
|
+
'__a(__args': ({}, path) => {
|
|
297
|
+
return true;
|
|
298
|
+
},
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
export const match = () => ({
|
|
302
|
+
'__a(__args': ({}, path) => {
|
|
303
|
+
return '';
|
|
304
|
+
},
|
|
305
|
+
});
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### ✅ Example of correct code
|
|
309
|
+
|
|
310
|
+
```js
|
|
311
|
+
export const replace = () => ({
|
|
312
|
+
'__a(__args': (vars, path) => {
|
|
313
|
+
return true;
|
|
314
|
+
},
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
export const match = () => ({
|
|
318
|
+
'__a(__args': (vars, path) => {
|
|
319
|
+
return '';
|
|
320
|
+
},
|
|
321
|
+
});
|
|
322
|
+
```
|
|
323
|
+
|
|
286
324
|
## apply-declare
|
|
287
325
|
|
|
288
326
|
Better to use [`Declareator`](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#declarator) instead of `operator.declare()`.
|
|
@@ -33,7 +33,9 @@ module.exports.replace = () => ({
|
|
|
33
33
|
't.noTransform(__a)': transform,
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
const isTest = (path) => compare(path, 'test(__a, (t) => __body)'
|
|
36
|
+
const isTest = (path) => compare(path, 'test(__a, (t) => __body)', {
|
|
37
|
+
findUp: false,
|
|
38
|
+
});
|
|
37
39
|
|
|
38
40
|
const check = ({__a}, path) => {
|
|
39
41
|
const name = __a.value;
|
|
@@ -41,20 +43,14 @@ const check = ({__a}, path) => {
|
|
|
41
43
|
if (FIXTURE.includes(name))
|
|
42
44
|
return false;
|
|
43
45
|
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
if (!testPath)
|
|
47
|
-
return false;
|
|
48
|
-
|
|
49
|
-
const [str] = testPath.parentPath.parentPath.node.arguments;
|
|
46
|
+
const str = getTestNodeArgument(name, path);
|
|
50
47
|
|
|
51
48
|
return !str.value.includes(name);
|
|
52
49
|
};
|
|
53
50
|
|
|
54
51
|
const transform = ({__a}, path) => {
|
|
55
52
|
const name = __a.value;
|
|
56
|
-
const
|
|
57
|
-
const [str] = testPath.parentPath.parentPath.node.arguments;
|
|
53
|
+
const str = getTestNodeArgument(name, path);
|
|
58
54
|
|
|
59
55
|
const values = str.value.split(':');
|
|
60
56
|
const last = values
|
|
@@ -68,3 +64,17 @@ const transform = ({__a}, path) => {
|
|
|
68
64
|
|
|
69
65
|
return path;
|
|
70
66
|
};
|
|
67
|
+
|
|
68
|
+
const getTestNodeArgument = (value, path) => {
|
|
69
|
+
let testPath = path.find(isTest);
|
|
70
|
+
|
|
71
|
+
if (!testPath)
|
|
72
|
+
return {
|
|
73
|
+
value,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
if (testPath.isExpressionStatement())
|
|
77
|
+
testPath = testPath.get('expression');
|
|
78
|
+
|
|
79
|
+
return testPath.node.arguments[0];
|
|
80
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -57,6 +57,7 @@ const convertIncludeToTraverse = require('./convert-include-to-traverse');
|
|
|
57
57
|
const removeUselessPrinterOption = require('./remove-useless-printer-option');
|
|
58
58
|
const addPathArgToVisitors = require('./add-path-arg-to-visitors');
|
|
59
59
|
const applyFixtureNameToMessage = require('./apply-fixture-name-to-message');
|
|
60
|
+
const applyVars = require('./apply-vars');
|
|
60
61
|
|
|
61
62
|
module.exports.rules = {
|
|
62
63
|
'apply-processors-destructuring': applyProcessorsDestructuring,
|
|
@@ -116,4 +117,5 @@ module.exports.rules = {
|
|
|
116
117
|
'remove-useless-printer-option': removeUselessPrinterOption,
|
|
117
118
|
'add-path-arg-to-visitors': addPathArgToVisitors,
|
|
118
119
|
'apply-fixture-name-to-message': applyFixtureNameToMessage,
|
|
120
|
+
'apply-vars': applyVars,
|
|
119
121
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-putout",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.5.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",
|
|
@@ -39,8 +39,7 @@
|
|
|
39
39
|
"keywords": [
|
|
40
40
|
"putout",
|
|
41
41
|
"putout-plugin",
|
|
42
|
-
"plugin"
|
|
43
|
-
"putout"
|
|
42
|
+
"plugin"
|
|
44
43
|
],
|
|
45
44
|
"devDependencies": {
|
|
46
45
|
"@putout/plugin-nodejs": "*",
|