@putout/engine-runner 13.7.0 → 14.0.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
@@ -237,6 +237,7 @@ Stores is preferred way of keeping 🐊**Putout** data, `traverse` init function
237
237
  of handling variables will most likely will lead to bugs. There is 3 store types:
238
238
 
239
239
  - ✅`listStore`;
240
+ - ✅`pathStore`;
240
241
  - ✅`store`;
241
242
  - ✅`upstore`;
242
243
  - ✅`uplist`;
@@ -275,6 +276,34 @@ module.exports.traverse = ({listStore}) => ({
275
276
  });
276
277
  ```
277
278
 
279
+ ### `pathStore`
280
+
281
+ When you want additional check that `path` not removed.
282
+
283
+ ```js
284
+ debugger;
285
+ const hello = '';
286
+ ```
287
+
288
+ Let's process it!
289
+
290
+ ```js
291
+ module.exports.traverse = ({pathStore}) => ({
292
+ 'debugger'(path) {
293
+ pathStore(path);
294
+ path.remove();
295
+ },
296
+
297
+ Program: {
298
+ exit() {
299
+ console.log(listStore());
300
+ // returns
301
+ [];
302
+ },
303
+ },
304
+ });
305
+ ```
306
+
278
307
  ### `store`
279
308
 
280
309
  When you need `key-value` use `store`:
@@ -11,6 +11,7 @@ const {
11
11
  mapStore,
12
12
  upStore,
13
13
  upListStore,
14
+ pathStore,
14
15
  } = require('./store');
15
16
 
16
17
  const shouldSkip = (a) => !a.parent;
@@ -40,6 +41,7 @@ module.exports = (pluginsToMerge, {fix, shebang, template}) => {
40
41
  store,
41
42
  upstore,
42
43
  listStore,
44
+ pathStore,
43
45
  uplist,
44
46
  } = getStore(plugin, {
45
47
  fix,
@@ -55,6 +57,7 @@ module.exports = (pluginsToMerge, {fix, shebang, template}) => {
55
57
  push,
56
58
  store,
57
59
  listStore,
60
+ pathStore,
58
61
  upstore,
59
62
  uplist,
60
63
  generate,
@@ -94,6 +97,7 @@ function getStore(plugin, {fix, rule, shebang, msg, options}) {
94
97
  const upstore = upStore();
95
98
  const placesStore = listStore();
96
99
  const uplist = upListStore();
100
+ const paths = pathStore();
97
101
 
98
102
  const push = (path) => {
99
103
  const position = getPosition(path, shebang);
@@ -117,6 +121,7 @@ function getStore(plugin, {fix, rule, shebang, msg, options}) {
117
121
  list.clear();
118
122
  upstore.clear();
119
123
  uplist.clear();
124
+ paths.clear();
120
125
 
121
126
  return placesStore.clear();
122
127
  };
@@ -128,6 +133,7 @@ function getStore(plugin, {fix, rule, shebang, msg, options}) {
128
133
  listStore: list,
129
134
  upstore,
130
135
  uplist,
136
+ pathStore: paths,
131
137
  };
132
138
  }
133
139
 
package/lib/store.js CHANGED
@@ -7,27 +7,12 @@ const {
7
7
  } = Object;
8
8
 
9
9
  const toArray = (a) => Array.from(a);
10
+ const isNotRemoved = (a) => a.node;
11
+ const notRemoved = (a) => toArray(a).filter(isNotRemoved);
12
+ const id = (a) => a;
10
13
 
11
- module.exports.listStore = (list = new Set()) => {
12
- const fn = (...args) => {
13
- if (!args.length)
14
- return Array.from(list);
15
-
16
- const [a] = args;
17
- list.add(a);
18
-
19
- return Array.from(list);
20
- };
21
-
22
- fn.clear = () => {
23
- const a = list;
24
- list = new Set();
25
-
26
- return Array.from(a);
27
- };
28
-
29
- return fn;
30
- };
14
+ module.exports.listStore = createListStore();
15
+ module.exports.pathStore = createListStore(notRemoved);
31
16
 
32
17
  module.exports.mapStore = createStore({
33
18
  get(map) {
@@ -82,3 +67,23 @@ function createStore({set, get}) {
82
67
  };
83
68
  }
84
69
 
70
+ function createListStore(returns = id) {
71
+ return (list = new Set()) => {
72
+ const fn = (...args) => {
73
+ if (!args.length)
74
+ return returns(toArray(list));
75
+
76
+ const [a] = args;
77
+ list.add(a);
78
+ };
79
+
80
+ fn.clear = () => {
81
+ const a = list;
82
+ list = new Set();
83
+
84
+ return returns(toArray(a));
85
+ };
86
+
87
+ return fn;
88
+ };
89
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/engine-runner",
3
- "version": "13.7.0",
3
+ "version": "14.0.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "run putout plugins",
@@ -44,8 +44,8 @@
44
44
  "@babel/plugin-codemod-optional-catch-binding": "^7.7.4",
45
45
  "c8": "^7.5.0",
46
46
  "eslint": "^8.0.1",
47
- "eslint-plugin-node": "^11.0.0",
48
- "eslint-plugin-putout": "^15.0.0",
47
+ "eslint-plugin-n": "^15.2.4",
48
+ "eslint-plugin-putout": "^16.0.0",
49
49
  "just-camel-case": "^4.0.2",
50
50
  "lerna": "^5.0.0",
51
51
  "madrun": "^9.0.0",