@putout/plugin-putout 22.5.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 +30 -0
- package/lib/declare-template-variables/index.js +50 -0
- package/lib/index.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,6 +61,7 @@ npm i @putout/plugin-putout -D
|
|
|
61
61
|
- ✅ [convert-url-to-dirname](#convert-url-to-dirname);
|
|
62
62
|
- ✅ [create-test](#create-test);
|
|
63
63
|
- ✅ [declare](#declare);
|
|
64
|
+
- ✅ [declare-template-variables](#declare-template-variables);
|
|
64
65
|
- ✅ [includer](#includer);
|
|
65
66
|
- ✅ [move-require-on-top-level](#move-require-on-top-level);
|
|
66
67
|
- ✅ [remove-empty-array-from-process](#remove-empty-array-from-process);
|
|
@@ -127,6 +128,7 @@ npm i @putout/plugin-putout -D
|
|
|
127
128
|
"putout/create-test": "on",
|
|
128
129
|
"putout/shorten-imports": "on",
|
|
129
130
|
"putout/declare": "on",
|
|
131
|
+
"putout/declare-template-variables": "on",
|
|
130
132
|
"putout/includer": "on",
|
|
131
133
|
"putout/move-require-on-top-level": "on",
|
|
132
134
|
"putout/replace-test-message": "on",
|
|
@@ -870,6 +872,34 @@ compare(a, 'const __a = __b');
|
|
|
870
872
|
isIdentifier(a);
|
|
871
873
|
```
|
|
872
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
|
+
|
|
873
903
|
## add-places-to-compare-places"
|
|
874
904
|
|
|
875
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
|
@@ -58,6 +58,7 @@ 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
60
|
const applyVars = require('./apply-vars');
|
|
61
|
+
const declareTemplateVariables = require('./declare-template-variables');
|
|
61
62
|
|
|
62
63
|
module.exports.rules = {
|
|
63
64
|
'apply-processors-destructuring': applyProcessorsDestructuring,
|
|
@@ -118,4 +119,5 @@ module.exports.rules = {
|
|
|
118
119
|
'add-path-arg-to-visitors': addPathArgToVisitors,
|
|
119
120
|
'apply-fixture-name-to-message': applyFixtureNameToMessage,
|
|
120
121
|
'apply-vars': applyVars,
|
|
122
|
+
'declare-template-variables': declareTemplateVariables,
|
|
121
123
|
};
|
package/package.json
CHANGED