@putout/plugin-putout 20.6.0 → 20.8.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
@@ -890,6 +890,28 @@ module.exports.traverse = ({store}) => ({
890
890
  });
891
891
  ```
892
892
 
893
+ - [`listStore``](https://github.com/coderaiser/putout/blob/master/packages/engine-runner/README.md#liststore)
894
+
895
+ ### ❌ Example of incorrect code
896
+
897
+ ```js
898
+ export const traverse = () => ({
899
+ ImportDeclaration(path) {
900
+ listStore(path);
901
+ },
902
+ });
903
+ ```
904
+
905
+ ### ✅ Example of correct code
906
+
907
+ ```js
908
+ module.exports.traverse = ({listStore}) => ({
909
+ ImportDeclaration(path) {
910
+ listStore(path);
911
+ },
912
+ });
913
+ ```
914
+
893
915
  - [`pathStore`](https://github.com/coderaiser/putout/blob/master/packages/engine-runner/README.md#pathstore)
894
916
 
895
917
  ### ❌ Example of incorrect code
@@ -12,6 +12,7 @@ const {
12
12
  const defaultNames = [
13
13
  'push',
14
14
  'store',
15
+ 'listStore',
15
16
  'pathStore',
16
17
  ];
17
18
 
@@ -38,79 +38,91 @@ module.exports.fix = ({mainPath}) => {
38
38
  };
39
39
 
40
40
  module.exports.traverse = ({push}) => ({
41
- 'module.exports.replace = () => __a': (path) => {
42
- if (get(path))
43
- return;
41
+ 'module.exports.replace = () => __a': createTraverseReplacer(push),
42
+ 'export const replace = () => __a': createTraverseReplacer(push),
43
+ });
44
+
45
+ function getProperties(path) {
46
+ const props = `body.properties`;
47
+
48
+ if (path.isExportNamedDeclaration())
49
+ return path.get(`declaration.declarations.0.init.${props}`);
50
+
51
+ return path.get(`right.${props}`);
52
+ }
53
+
54
+ const createTraverseReplacer = (push) => (path) => {
55
+ if (get(path))
56
+ return;
57
+
58
+ if (hasMatch(path))
59
+ return;
60
+
61
+ for (const propertyPath of getProperties(path)) {
62
+ const template = extractValue(propertyPath);
44
63
 
45
- if (hasMatch(path))
46
- return;
64
+ if (!template)
65
+ continue;
47
66
 
48
- for (const propertyPath of path.get('right.body.properties')) {
49
- const template = extractValue(propertyPath);
50
-
51
- if (!template)
52
- continue;
53
-
54
- const [parseError, key] = parseKey(propertyPath);
55
-
56
- if (parseError) {
57
- push({
58
- error: parseError,
59
- mainPath: path,
60
- path: propertyPath,
61
- });
62
-
63
- return;
64
- }
65
-
66
- const [generateError, keyCode] = generateCode(path, key);
67
-
68
- if (generateError) {
69
- push({
70
- error: generateError,
71
- mainPath: path,
72
- path: propertyPath,
73
- });
74
-
75
- return;
76
- }
77
-
78
- const [transformError, result] = tryCatch(putout, keyCode, {
79
- printer: 'putout',
80
- fix: true,
81
- isTS: true,
82
- plugins: [
83
- ['evaluate', {
84
- report: noop,
85
- replace: () => ({
86
- [key]: template,
87
- }),
88
- }],
89
- ],
67
+ const [parseError, key] = parseKey(propertyPath);
68
+
69
+ if (parseError) {
70
+ push({
71
+ error: parseError,
72
+ mainPath: path,
73
+ path: propertyPath,
90
74
  });
91
75
 
92
- if (transformError) {
93
- push({
94
- error: transformError,
95
- mainPath: path,
96
- path: propertyPath,
97
- });
98
-
99
- return;
100
- }
76
+ return;
77
+ }
78
+
79
+ const [generateError, keyCode] = generateCode(path, key);
80
+
81
+ if (generateError) {
82
+ push({
83
+ error: generateError,
84
+ mainPath: path,
85
+ path: propertyPath,
86
+ });
101
87
 
102
- const code = result.code.slice(0, -1);
103
- const [error, is] = tryCatch(compare, rmSemi(code), template);
88
+ return;
89
+ }
90
+
91
+ const [transformError, result] = tryCatch(putout, keyCode, {
92
+ printer: 'putout',
93
+ fix: true,
94
+ isTS: true,
95
+ plugins: [
96
+ ['evaluate', {
97
+ report: noop,
98
+ replace: () => ({
99
+ [key]: template,
100
+ }),
101
+ }],
102
+ ],
103
+ });
104
+
105
+ if (transformError) {
106
+ push({
107
+ error: transformError,
108
+ mainPath: path,
109
+ path: propertyPath,
110
+ });
104
111
 
105
- if (error || !is)
106
- push({
107
- code,
108
- mainPath: path,
109
- path: propertyPath,
110
- });
112
+ return;
111
113
  }
112
- },
113
- });
114
+
115
+ const code = result.code.slice(0, -1);
116
+ const [error, is] = tryCatch(compare, rmSemi(code), template);
117
+
118
+ if (error || !is)
119
+ push({
120
+ code,
121
+ mainPath: path,
122
+ path: propertyPath,
123
+ });
124
+ }
125
+ };
114
126
 
115
127
  function parseKey(propertyPath) {
116
128
  const keyPath = propertyPath.get('key');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "20.6.0",
3
+ "version": "20.8.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,7 +39,7 @@
39
39
  "devDependencies": {
40
40
  "@putout/plugin-tape": "*",
41
41
  "@putout/test": "^10.0.0",
42
- "c8": "^9.0.0",
42
+ "c8": "^10.0.0",
43
43
  "eslint": "^9.0.0",
44
44
  "eslint-plugin-n": "^17.0.0",
45
45
  "eslint-plugin-putout": "^22.0.0",