@putout/engine-runner 12.6.0 β 13.1.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 +11 -9
- package/lib/include.js +6 -2
- package/lib/run-fix.js +8 -0
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/engine-runner.svg?style=flat&longCache=true
|
|
4
4
|
[NPMURL]: https://npmjs.org/package/@putout/engine-runner"npm"
|
|
5
5
|
|
|
6
|
-
Run π[
|
|
6
|
+
Run π[**Putout**](https://github.com/coderaiser/putout) plugins.
|
|
7
7
|
|
|
8
8
|
## Install
|
|
9
9
|
|
|
@@ -13,18 +13,20 @@ npm i @putout/engine-runner
|
|
|
13
13
|
|
|
14
14
|
## Supported Plugin Types
|
|
15
15
|
|
|
16
|
-
There is a couple plugin types supported by
|
|
16
|
+
There is a couple plugin types supported by π**Putout**:
|
|
17
17
|
|
|
18
18
|
- β
[`Replacer`](#replacer)
|
|
19
19
|
- β
[`Includer`](#includer)
|
|
20
20
|
- β
[`Traverser`](#traverser)
|
|
21
21
|
- β
[`Finder`](#finder)
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
All of them supports subset of **JavaScript** π¦[**PutoutScript**](https://github.com/coderaiser/putout/blob/master/docs/putout-script.md#-putoutscript) described in [`@putout/compare`](https://github.com/coderaiser/putout/tree/master/packages/compare#readme).
|
|
24
|
+
|
|
25
|
+
They goes from simplest to hardest. Let's start from **Replacer**.
|
|
24
26
|
|
|
25
27
|
### Replacer
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
**Replacer** converts code in declarative way. Simplest possible form, no need to use `fix`. Just `from` and `to` parts
|
|
28
30
|
according to [`template variables syntax`](https://github.com/coderaiser/putout/tree/master/packages/compare#supported-template-variables).
|
|
29
31
|
|
|
30
32
|
Simplest replace example:
|
|
@@ -61,7 +63,7 @@ Simplest remove example:
|
|
|
61
63
|
module.exports.report = () => 'debugger should not be used';
|
|
62
64
|
|
|
63
65
|
module.exports.replace = () => ({
|
|
64
|
-
|
|
66
|
+
debugger: '',
|
|
65
67
|
});
|
|
66
68
|
```
|
|
67
69
|
|
|
@@ -160,7 +162,7 @@ module.exports.filter = (path) => {
|
|
|
160
162
|
const __ = 'hello';
|
|
161
163
|
```
|
|
162
164
|
|
|
163
|
-
Where `__` can be any node. All this possible with help of [@putout/compare](https://github.com/coderaiser/putout/tree/master/packages/compare). Templates format supported in `traverse` and `find` plugins as well.
|
|
165
|
+
Where `__` can be any node. All this possible with help of [@putout/compare](https://github.com/coderaiser/putout/tree/master/packages/compare#readme). Templates format supported in `traverse` and `find` plugins as well.
|
|
164
166
|
|
|
165
167
|
### Traverser
|
|
166
168
|
|
|
@@ -208,8 +210,8 @@ const {runPlugins} = require('@putout/engine-runner');
|
|
|
208
210
|
const {parse} = require('@putout/engin-parser');
|
|
209
211
|
|
|
210
212
|
const plugins = [{
|
|
211
|
-
rule:
|
|
212
|
-
msg:
|
|
213
|
+
rule: 'remove-debugger',
|
|
214
|
+
msg: '', // optional
|
|
213
215
|
options: {}, // optional
|
|
214
216
|
plugin: {
|
|
215
217
|
include: () => ['debugger'],
|
|
@@ -231,7 +233,7 @@ const places = runPlugins({
|
|
|
231
233
|
|
|
232
234
|
## Stores
|
|
233
235
|
|
|
234
|
-
Stores is preferred way of keeping
|
|
236
|
+
Stores is preferred way of keeping π**Putout** data, `traverse` init function called only once, and any other way
|
|
235
237
|
of handling variables will most likely will lead to bugs. There is 3 store types:
|
|
236
238
|
|
|
237
239
|
- β
`listStore`;
|
package/lib/include.js
CHANGED
|
@@ -17,8 +17,8 @@ module.exports = ({rule, plugin, msg, options}) => {
|
|
|
17
17
|
filter = good,
|
|
18
18
|
} = plugin;
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
validate('include', include);
|
|
21
|
+
validate('report', report);
|
|
22
22
|
|
|
23
23
|
const traverse = getTraverse(include(), filter, rule);
|
|
24
24
|
|
|
@@ -64,3 +64,7 @@ const getTraverse = (include, filter, rule) => ({push, options}) => {
|
|
|
64
64
|
return result;
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
+
function validate(name, fn) {
|
|
68
|
+
if (!isFn(fn))
|
|
69
|
+
throw Error(`βοΈ Looks like '${name}' is not a 'function' but '${typeof fn}' with value: '${stringify(fn)}'. More on using Includer: https://git.io/JqcMn`);
|
|
70
|
+
}
|
package/lib/run-fix.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
const tryCatch = require('try-catch');
|
|
4
4
|
const debug = require('debug')('putout:runner:fix');
|
|
5
5
|
const {enabled} = debug;
|
|
6
|
+
const {stringify} = JSON;
|
|
7
|
+
const isFn = (a) => typeof a === 'function';
|
|
6
8
|
|
|
7
9
|
const tryToFix = (fix, {path, position, options}) => {
|
|
8
10
|
const [e] = tryCatch(fix, path, {options});
|
|
@@ -25,6 +27,7 @@ module.exports = (is, fix, {path, rule, position, options}) => {
|
|
|
25
27
|
return;
|
|
26
28
|
|
|
27
29
|
enabled && debug(`fix: ${rule}`, position, path.toString());
|
|
30
|
+
validate('fix', fix);
|
|
28
31
|
|
|
29
32
|
tryToFix(fix, {
|
|
30
33
|
path,
|
|
@@ -33,3 +36,8 @@ module.exports = (is, fix, {path, rule, position, options}) => {
|
|
|
33
36
|
});
|
|
34
37
|
};
|
|
35
38
|
|
|
39
|
+
function validate(name, fn) {
|
|
40
|
+
if (!isFn(fn))
|
|
41
|
+
throw Error(`βοΈ Looks like '${name}' is not a 'function' but '${typeof fn}' with value: '${stringify(fn)}'. More on writing πPutout Plugins: https://git.io/JqcMn`);
|
|
42
|
+
}
|
|
43
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/engine-runner",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "13.1.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "run putout plugins",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@babel/traverse": "^7.12.7",
|
|
28
28
|
"@babel/types": "^7.12.7",
|
|
29
|
-
"@putout/compare": "^
|
|
30
|
-
"@putout/engine-parser": "^
|
|
29
|
+
"@putout/compare": "^9.0.0",
|
|
30
|
+
"@putout/engine-parser": "^5.0.0",
|
|
31
31
|
"@putout/operate": "^7.0.0",
|
|
32
32
|
"debug": "^4.1.1",
|
|
33
33
|
"jessy": "^3.0.0",
|
|
@@ -46,19 +46,19 @@
|
|
|
46
46
|
"c8": "^7.5.0",
|
|
47
47
|
"eslint": "^8.0.1",
|
|
48
48
|
"eslint-plugin-node": "^11.0.0",
|
|
49
|
-
"eslint-plugin-putout": "^
|
|
49
|
+
"eslint-plugin-putout": "^14.0.0",
|
|
50
50
|
"just-camel-case": "^4.0.2",
|
|
51
51
|
"lerna": "^4.0.0",
|
|
52
|
-
"madrun": "^
|
|
52
|
+
"madrun": "^9.0.0",
|
|
53
53
|
"mock-require": "^3.0.3",
|
|
54
54
|
"montag": "^1.0.0",
|
|
55
55
|
"nodemon": "^2.0.1",
|
|
56
56
|
"putout": "*",
|
|
57
|
-
"supertape": "^
|
|
57
|
+
"supertape": "^7.0.0"
|
|
58
58
|
},
|
|
59
59
|
"license": "MIT",
|
|
60
60
|
"engines": {
|
|
61
|
-
"node": ">=
|
|
61
|
+
"node": ">=16"
|
|
62
62
|
},
|
|
63
63
|
"publishConfig": {
|
|
64
64
|
"access": "public"
|