@putout/engine-runner 13.5.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 +35 -6
- package/lib/merge-visitors.js +7 -0
- package/lib/replace/index.js +4 -4
- package/lib/run-fix.js +5 -1
- package/lib/store.js +25 -19
- package/package.json +4 -5
package/README.md
CHANGED
|
@@ -211,8 +211,8 @@ const {parse} = require('@putout/engin-parser');
|
|
|
211
211
|
|
|
212
212
|
const plugins = [{
|
|
213
213
|
rule: 'remove-debugger',
|
|
214
|
-
msg: '',
|
|
215
|
-
options: {},
|
|
214
|
+
msg: '', // optional
|
|
215
|
+
options: {}, // optional
|
|
216
216
|
plugin: {
|
|
217
217
|
include: () => ['debugger'],
|
|
218
218
|
fix: (path) => path.remove(),
|
|
@@ -223,11 +223,11 @@ const plugins = [{
|
|
|
223
223
|
const ast = parse('const m = "hi"; debugger');
|
|
224
224
|
const places = runPlugins({
|
|
225
225
|
ast,
|
|
226
|
-
shebang: false,
|
|
227
|
-
fix: true,
|
|
228
|
-
fixCount: 1,
|
|
226
|
+
shebang: false, // default
|
|
227
|
+
fix: true, // default
|
|
228
|
+
fixCount: 1, // default
|
|
229
229
|
plugins,
|
|
230
|
-
parser: 'babel',
|
|
230
|
+
parser: 'babel', // default
|
|
231
231
|
});
|
|
232
232
|
```
|
|
233
233
|
|
|
@@ -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`:
|
package/lib/merge-visitors.js
CHANGED
|
@@ -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,8 @@ function getStore(plugin, {fix, rule, shebang, msg, options}) {
|
|
|
117
121
|
list.clear();
|
|
118
122
|
upstore.clear();
|
|
119
123
|
uplist.clear();
|
|
124
|
+
paths.clear();
|
|
125
|
+
|
|
120
126
|
return placesStore.clear();
|
|
121
127
|
};
|
|
122
128
|
|
|
@@ -127,6 +133,7 @@ function getStore(plugin, {fix, rule, shebang, msg, options}) {
|
|
|
127
133
|
listStore: list,
|
|
128
134
|
upstore,
|
|
129
135
|
uplist,
|
|
136
|
+
pathStore: paths,
|
|
130
137
|
};
|
|
131
138
|
}
|
|
132
139
|
|
package/lib/replace/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const isString = (a) => typeof a === 'string';
|
|
4
|
-
|
|
5
3
|
const {template} = require('@putout/engine-parser');
|
|
4
|
+
|
|
6
5
|
const {
|
|
7
6
|
remove,
|
|
8
7
|
replaceWith,
|
|
@@ -14,9 +13,10 @@ const {
|
|
|
14
13
|
setValues,
|
|
15
14
|
} = require('@putout/compare');
|
|
16
15
|
const debug = require('debug')('putout:runner:replace');
|
|
17
|
-
|
|
18
16
|
const maybeArray = require('../maybe-array');
|
|
17
|
+
|
|
19
18
|
const watermark = require('./watermark');
|
|
19
|
+
const isString = (a) => typeof a === 'string';
|
|
20
20
|
|
|
21
21
|
const log = (from, path) => {
|
|
22
22
|
debug.enabled && debug(`${from} -> ${path}\n`);
|
|
@@ -76,7 +76,7 @@ const fix = (from, to, path) => {
|
|
|
76
76
|
if (mark.has())
|
|
77
77
|
return;
|
|
78
78
|
|
|
79
|
-
if (!compare(path, nodeFrom))
|
|
79
|
+
if (!compare(path, nodeFrom, {findUp: false}))
|
|
80
80
|
return;
|
|
81
81
|
|
|
82
82
|
const waysFrom = findVarsWays(nodeFrom);
|
package/lib/run-fix.js
CHANGED
|
@@ -4,7 +4,9 @@ const tryCatch = require('try-catch');
|
|
|
4
4
|
const debug = require('debug')('putout:runner:fix');
|
|
5
5
|
const {enabled} = debug;
|
|
6
6
|
const {stringify} = JSON;
|
|
7
|
+
|
|
7
8
|
const isFn = (a) => typeof a === 'function';
|
|
9
|
+
const getPath = (path) => path.path || path;
|
|
8
10
|
|
|
9
11
|
const tryToFix = (fix, {path, position, options}) => {
|
|
10
12
|
const [e] = tryCatch(fix, path, {options});
|
|
@@ -26,7 +28,9 @@ module.exports = (is, fix, {path, rule, position, options}) => {
|
|
|
26
28
|
if (!is)
|
|
27
29
|
return;
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
if (enabled)
|
|
32
|
+
debug(`fix: ${rule}`, position, getPath(path).toString());
|
|
33
|
+
|
|
30
34
|
validate('fix', fix);
|
|
31
35
|
|
|
32
36
|
tryToFix(fix, {
|
package/lib/store.js
CHANGED
|
@@ -7,26 +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 = (
|
|
12
|
-
|
|
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
|
-
return Array.from(a);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
return fn;
|
|
29
|
-
};
|
|
14
|
+
module.exports.listStore = createListStore();
|
|
15
|
+
module.exports.pathStore = createListStore(notRemoved);
|
|
30
16
|
|
|
31
17
|
module.exports.mapStore = createStore({
|
|
32
18
|
get(map) {
|
|
@@ -81,3 +67,23 @@ function createStore({set, get}) {
|
|
|
81
67
|
};
|
|
82
68
|
}
|
|
83
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": "
|
|
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",
|
|
@@ -42,13 +42,12 @@
|
|
|
42
42
|
],
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@babel/plugin-codemod-optional-catch-binding": "^7.7.4",
|
|
45
|
-
"@cloudcmd/stub": "^3.0.0",
|
|
46
45
|
"c8": "^7.5.0",
|
|
47
46
|
"eslint": "^8.0.1",
|
|
48
|
-
"eslint-plugin-
|
|
49
|
-
"eslint-plugin-putout": "^
|
|
47
|
+
"eslint-plugin-n": "^15.2.4",
|
|
48
|
+
"eslint-plugin-putout": "^16.0.0",
|
|
50
49
|
"just-camel-case": "^4.0.2",
|
|
51
|
-
"lerna": "^
|
|
50
|
+
"lerna": "^5.0.0",
|
|
52
51
|
"madrun": "^9.0.0",
|
|
53
52
|
"mock-require": "^3.0.3",
|
|
54
53
|
"montag": "^1.0.0",
|