@putout/plugin-putout 22.4.0 → 22.6.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 +68 -0
- package/lib/apply-vars/index.js +7 -0
- package/lib/declare-template-variables/index.js +50 -0
- package/lib/index.js +4 -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);
|
|
@@ -60,6 +61,7 @@ npm i @putout/plugin-putout -D
|
|
|
60
61
|
- ✅ [convert-url-to-dirname](#convert-url-to-dirname);
|
|
61
62
|
- ✅ [create-test](#create-test);
|
|
62
63
|
- ✅ [declare](#declare);
|
|
64
|
+
- ✅ [declare-template-variables](#declare-template-variables);
|
|
63
65
|
- ✅ [includer](#includer);
|
|
64
66
|
- ✅ [move-require-on-top-level](#move-require-on-top-level);
|
|
65
67
|
- ✅ [remove-empty-array-from-process](#remove-empty-array-from-process);
|
|
@@ -92,6 +94,7 @@ npm i @putout/plugin-putout -D
|
|
|
92
94
|
"putout/apply-remove": "on",
|
|
93
95
|
"putout/apply-insert-before": "on",
|
|
94
96
|
"putout/apply-insert-after": "on",
|
|
97
|
+
"putout/apply-vars": "on",
|
|
95
98
|
"putout/apply-short-processors": "on",
|
|
96
99
|
"putout/apply-namespace-specifier": "on",
|
|
97
100
|
"putout/apply-for-of-to-track-file": "on",
|
|
@@ -125,6 +128,7 @@ npm i @putout/plugin-putout -D
|
|
|
125
128
|
"putout/create-test": "on",
|
|
126
129
|
"putout/shorten-imports": "on",
|
|
127
130
|
"putout/declare": "on",
|
|
131
|
+
"putout/declare-template-variables": "on",
|
|
128
132
|
"putout/includer": "on",
|
|
129
133
|
"putout/move-require-on-top-level": "on",
|
|
130
134
|
"putout/replace-test-message": "on",
|
|
@@ -283,6 +287,42 @@ export const fix = (path) => {
|
|
|
283
287
|
};
|
|
284
288
|
```
|
|
285
289
|
|
|
290
|
+
## apply-vars
|
|
291
|
+
|
|
292
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/f96aaef6c54049ca91497a17f7a4b88a/b960916e73a7f51c1c0425ad9a3f304452c0d159).
|
|
293
|
+
|
|
294
|
+
### ❌ Example of incorrect code
|
|
295
|
+
|
|
296
|
+
```js
|
|
297
|
+
export const replace = () => ({
|
|
298
|
+
'__a(__args': ({}, path) => {
|
|
299
|
+
return true;
|
|
300
|
+
},
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
export const match = () => ({
|
|
304
|
+
'__a(__args': ({}, path) => {
|
|
305
|
+
return '';
|
|
306
|
+
},
|
|
307
|
+
});
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### ✅ Example of correct code
|
|
311
|
+
|
|
312
|
+
```js
|
|
313
|
+
export const replace = () => ({
|
|
314
|
+
'__a(__args': (vars, path) => {
|
|
315
|
+
return true;
|
|
316
|
+
},
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
export const match = () => ({
|
|
320
|
+
'__a(__args': (vars, path) => {
|
|
321
|
+
return '';
|
|
322
|
+
},
|
|
323
|
+
});
|
|
324
|
+
```
|
|
325
|
+
|
|
286
326
|
## apply-declare
|
|
287
327
|
|
|
288
328
|
Better to use [`Declareator`](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#declarator) instead of `operator.declare()`.
|
|
@@ -832,6 +872,34 @@ compare(a, 'const __a = __b');
|
|
|
832
872
|
isIdentifier(a);
|
|
833
873
|
```
|
|
834
874
|
|
|
875
|
+
## declare-template-variables
|
|
876
|
+
|
|
877
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/71ae86cc372dca8adc79bf53c49e8d5f/c9c8517ee932c18abcfda10c0515253b907ee485).
|
|
878
|
+
|
|
879
|
+
### ❌ Example of incorrect code
|
|
880
|
+
|
|
881
|
+
```js
|
|
882
|
+
export const match = () => ({
|
|
883
|
+
'__a(__args': (vars, path) => {
|
|
884
|
+
fn(x);
|
|
885
|
+
|
|
886
|
+
return __args[__a];
|
|
887
|
+
},
|
|
888
|
+
});
|
|
889
|
+
```
|
|
890
|
+
|
|
891
|
+
### ✅ Example of correct code
|
|
892
|
+
|
|
893
|
+
```js
|
|
894
|
+
export const match = () => ({
|
|
895
|
+
'__a(__args': ({__args, __a}, path) => {
|
|
896
|
+
fn(x);
|
|
897
|
+
|
|
898
|
+
return __args[__a];
|
|
899
|
+
},
|
|
900
|
+
});
|
|
901
|
+
```
|
|
902
|
+
|
|
835
903
|
## add-places-to-compare-places"
|
|
836
904
|
|
|
837
905
|
### ❌ Example of incorrect code
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types} = require('putout');
|
|
4
|
+
const {
|
|
5
|
+
ObjectPattern,
|
|
6
|
+
isIdentifier,
|
|
7
|
+
ObjectProperty,
|
|
8
|
+
} = types;
|
|
9
|
+
|
|
10
|
+
const SHORTHAND = true;
|
|
11
|
+
const COMPUTED = false;
|
|
12
|
+
|
|
13
|
+
module.exports.report = ({node}) => {
|
|
14
|
+
const {name} = node;
|
|
15
|
+
return `Declare template variable '${name}'`;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
module.exports.fix = ({path, node}) => {
|
|
19
|
+
const [first] = path.node.params;
|
|
20
|
+
const property = ObjectProperty(node, node, COMPUTED, SHORTHAND);
|
|
21
|
+
|
|
22
|
+
if (isIdentifier(first)) {
|
|
23
|
+
path.node.params[0] = ObjectPattern([property]);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
path.node.params[0].properties.push(property);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
module.exports.traverse = ({push}) => ({
|
|
31
|
+
'(vars, path) => __body': (path) => {
|
|
32
|
+
path.traverse({
|
|
33
|
+
ReferencedIdentifier(refPath) {
|
|
34
|
+
const {node} = refPath;
|
|
35
|
+
const {name} = node;
|
|
36
|
+
|
|
37
|
+
if (!name.startsWith('__'))
|
|
38
|
+
return;
|
|
39
|
+
|
|
40
|
+
if (refPath.scope.bindings[name])
|
|
41
|
+
return;
|
|
42
|
+
|
|
43
|
+
push({
|
|
44
|
+
path,
|
|
45
|
+
node,
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
});
|
package/lib/index.js
CHANGED
|
@@ -57,6 +57,8 @@ 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');
|
|
61
|
+
const declareTemplateVariables = require('./declare-template-variables');
|
|
60
62
|
|
|
61
63
|
module.exports.rules = {
|
|
62
64
|
'apply-processors-destructuring': applyProcessorsDestructuring,
|
|
@@ -116,4 +118,6 @@ module.exports.rules = {
|
|
|
116
118
|
'remove-useless-printer-option': removeUselessPrinterOption,
|
|
117
119
|
'add-path-arg-to-visitors': addPathArgToVisitors,
|
|
118
120
|
'apply-fixture-name-to-message': applyFixtureNameToMessage,
|
|
121
|
+
'apply-vars': applyVars,
|
|
122
|
+
'declare-template-variables': declareTemplateVariables,
|
|
119
123
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-putout",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.6.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": "*",
|