@putout/plugin-putout 8.0.0 → 8.3.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 +83 -7
- package/lib/apply-async-formatter/index.js +47 -0
- package/lib/check-replace-code/index.js +4 -0
- package/lib/convert-destructuring-to-identifier/index.js +1 -0
- package/lib/convert-putout-test-to-create-test/index.js +14 -0
- package/lib/index.js +3 -0
- package/lib/move-require-on-top-level/index.js +76 -0
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
# @putout/plugin-putout [![NPM version][NPMIMGURL]][NPMURL]
|
|
1
|
+
# @putout/plugin-putout [![NPM version][NPMIMGURL]][NPMURL]
|
|
2
2
|
|
|
3
3
|
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-putout.svg?style=flat&longCache=true
|
|
4
4
|
[NPMURL]: https://npmjs.org/package/@putout/plugin-putout"npm"
|
|
5
|
-
[DependencyStatusURL]: https://david-dm.org/coderaiser/putout?path=packages/plugin-putout
|
|
6
|
-
[DependencyStatusIMGURL]: https://david-dm.org/coderaiser/putout.svg?path=packages/plugin-putout
|
|
7
5
|
|
|
8
|
-
`putout
|
|
6
|
+
🐊[`Putout`](https://github.com/coderaiser/putout) plugin helps with 🐊`Putout` plugins development.
|
|
9
7
|
|
|
10
8
|
## Install
|
|
11
9
|
|
|
@@ -19,7 +17,9 @@ npm i @putout/plugin-putout -D
|
|
|
19
17
|
{
|
|
20
18
|
"rules": {
|
|
21
19
|
"putout/apply-processors-destructuring": "on",
|
|
20
|
+
"putout/apply-async-formatter": "on",
|
|
22
21
|
"putout/add-args": "on",
|
|
22
|
+
"putout/convert-putout-test-to-create-test": "on",
|
|
23
23
|
"putout/convert-to-no-transform-code": "on",
|
|
24
24
|
"putout/convert-replace-with": "on",
|
|
25
25
|
"putout/convert-replace-with-multiple": "on",
|
|
@@ -33,7 +33,8 @@ npm i @putout/plugin-putout -D
|
|
|
33
33
|
"putout/convert-add-argument-to-add-args": "on",
|
|
34
34
|
"putout/shorten-imports": "on",
|
|
35
35
|
"putout/check-replace-code": "on",
|
|
36
|
-
"putout/declare": "on"
|
|
36
|
+
"putout/declare": "on",
|
|
37
|
+
"putout/move-require-on-top-level": "on"
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
```
|
|
@@ -57,6 +58,49 @@ test('', async ({process}) => {
|
|
|
57
58
|
});
|
|
58
59
|
```
|
|
59
60
|
|
|
61
|
+
## apply-async-formatter
|
|
62
|
+
|
|
63
|
+
### ❌ Incorrect code example
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
test('formatter: codeframea', (t) => {
|
|
67
|
+
t.format(codeframe, 1);
|
|
68
|
+
t.end();
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### ✅ Correct code example
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
test('formatter: codeframea', async ({format}) => {
|
|
76
|
+
await format(codeframe, 1);
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## convert-putout-test-to-create-test"
|
|
81
|
+
|
|
82
|
+
Fixes results of [@putout/convert-commonjs-to-esm](https://github.com/coderaiser/putout/tree/master/packages/plugin-convert-commonjs-to-esm) work.
|
|
83
|
+
|
|
84
|
+
### ❌ Incorrect code example
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
import putoutTest from '@putout/test';
|
|
88
|
+
|
|
89
|
+
const test = putoutTest(__dirname, {
|
|
90
|
+
'remove-unused-variables': rmVars,
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### ✅ Correct code Example
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
import createTest from '@putout/test';
|
|
98
|
+
|
|
99
|
+
const test = createTest(__dirname, {
|
|
100
|
+
'remove-unused-variables': rmVars,
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
60
104
|
## convert-to-no-transform-code
|
|
61
105
|
|
|
62
106
|
### ❌ Incorrect code example
|
|
@@ -154,7 +198,6 @@ module.exports.replace = () => ({
|
|
|
154
198
|
'const __a = __b': ({}) => {
|
|
155
199
|
},
|
|
156
200
|
'const __c = __d': ({}, path) => {
|
|
157
|
-
|
|
158
201
|
},
|
|
159
202
|
});
|
|
160
203
|
```
|
|
@@ -287,7 +330,8 @@ module.exports.replace = () => ({
|
|
|
287
330
|
});
|
|
288
331
|
```
|
|
289
332
|
|
|
290
|
-
There is no `fix` for this rule, it used internally to be more confident about `test coverage`, because of declaration form, transforms cannon be checked by `nyc` and `c8`, and uncovered lines can find unfixable false possitives when running on code.
|
|
333
|
+
There is no `fix` for this rule, it used internally to be more confident about `test coverage`, because of declaration form, transforms cannon be checked by `nyc` and `c8`, and uncovered lines can find unfixable false possitives when running on code.
|
|
334
|
+
This is additional tests, if you forget to test some case (from a big list of rules that is supported) it will be checked with this `rule` and make transforms more stable.
|
|
291
335
|
|
|
292
336
|
## declare
|
|
293
337
|
|
|
@@ -352,6 +396,38 @@ module.exports = addArgs({
|
|
|
352
396
|
});
|
|
353
397
|
```
|
|
354
398
|
|
|
399
|
+
## move-require-on-top-level
|
|
400
|
+
|
|
401
|
+
### ❌ Incorrect code example
|
|
402
|
+
|
|
403
|
+
```js
|
|
404
|
+
const test = require('@putout/test')(__dirname, {
|
|
405
|
+
'remove-debugger': require('..'),
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
test('remove debugger: report', (t) => {
|
|
409
|
+
t.transform('debugger', {
|
|
410
|
+
'remove-debugger': require('..'),
|
|
411
|
+
});
|
|
412
|
+
t.end();
|
|
413
|
+
});
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
### ✅ Correct code Example
|
|
417
|
+
|
|
418
|
+
```js
|
|
419
|
+
const removeDebugger = require('..');
|
|
420
|
+
const test = require('@putout/test')(__dirname, {
|
|
421
|
+
'remove-debugger': removeDebugger,
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
test('remove debugger: report', (t) => {
|
|
425
|
+
const test = require('@putout/test')(__dirname, {
|
|
426
|
+
'remove-debugger': removeDebugger,
|
|
427
|
+
});
|
|
428
|
+
t.end();
|
|
429
|
+
});
|
|
430
|
+
```
|
|
355
431
|
|
|
356
432
|
## License
|
|
357
433
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
operator,
|
|
5
|
+
types,
|
|
6
|
+
} = require('putout');
|
|
7
|
+
|
|
8
|
+
const computed = true;
|
|
9
|
+
const shorthand = true;
|
|
10
|
+
|
|
11
|
+
const {
|
|
12
|
+
Identifier,
|
|
13
|
+
ObjectPattern,
|
|
14
|
+
ObjectProperty,
|
|
15
|
+
} = types;
|
|
16
|
+
|
|
17
|
+
const {compare} = operator;
|
|
18
|
+
|
|
19
|
+
module.exports.report = () => 'Use Async API to test Formatter';
|
|
20
|
+
|
|
21
|
+
module.exports.replace = () => ({
|
|
22
|
+
't.format(__args)': create('format'),
|
|
23
|
+
't.noFormat(__args)': create('noFormat'),
|
|
24
|
+
't.formatMany(__args)': create('formatMany'),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const create = (name) => (vars, path) => {
|
|
28
|
+
const {block} = path.scope;
|
|
29
|
+
const {body} = block.body;
|
|
30
|
+
const n = body.length - 1;
|
|
31
|
+
const nameId = Identifier(name);
|
|
32
|
+
|
|
33
|
+
block.async = true;
|
|
34
|
+
|
|
35
|
+
block.params = [
|
|
36
|
+
ObjectPattern([
|
|
37
|
+
ObjectProperty(nameId, nameId, !computed, shorthand),
|
|
38
|
+
]),
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
if (compare(body[n], 't.end()')) {
|
|
42
|
+
body.pop();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return `await ${name}(__args)`;
|
|
46
|
+
};
|
|
47
|
+
|
|
@@ -48,6 +48,10 @@ module.exports.traverse = ({push}) => ({
|
|
|
48
48
|
continue;
|
|
49
49
|
|
|
50
50
|
const {node} = propertyPath;
|
|
51
|
+
|
|
52
|
+
if (node.computed)
|
|
53
|
+
return false;
|
|
54
|
+
|
|
51
55
|
const key = extract(node.key);
|
|
52
56
|
const template = extract(node.value);
|
|
53
57
|
const [generateError, keyCode] = generateCode(path, key);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.report = () => `Use 'createTest' instead of 'putoutTest'`;
|
|
4
|
+
|
|
5
|
+
module.exports.filter = ({scope}) => !scope.bindings.createTest;
|
|
6
|
+
|
|
7
|
+
module.exports.include = () => [
|
|
8
|
+
'import putoutTest from "@putout/test"',
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
module.exports.fix = (path) => {
|
|
12
|
+
path.scope.rename('putoutTest', 'createTest');
|
|
13
|
+
};
|
|
14
|
+
|
package/lib/index.js
CHANGED
|
@@ -6,6 +6,8 @@ const getRule = (a) => ({
|
|
|
6
6
|
|
|
7
7
|
module.exports.rules = {
|
|
8
8
|
...getRule('apply-processors-destructuring'),
|
|
9
|
+
...getRule('apply-async-formatter'),
|
|
10
|
+
...getRule('convert-putout-test-to-create-test'),
|
|
9
11
|
...getRule('convert-to-no-transform-code'),
|
|
10
12
|
...getRule('convert-find-to-traverse'),
|
|
11
13
|
...getRule('convert-replace-with'),
|
|
@@ -24,5 +26,6 @@ module.exports.rules = {
|
|
|
24
26
|
...getRule('check-replace-code'),
|
|
25
27
|
...getRule('declare'),
|
|
26
28
|
...getRule('add-args'),
|
|
29
|
+
...getRule('move-require-on-top-level'),
|
|
27
30
|
};
|
|
28
31
|
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const justCamelCase = require('just-camel-case');
|
|
4
|
+
const {
|
|
5
|
+
types,
|
|
6
|
+
template,
|
|
7
|
+
} = require('putout');
|
|
8
|
+
|
|
9
|
+
const TEST = `
|
|
10
|
+
const test = require('@putout/test')(__dirname, {
|
|
11
|
+
__a: __b
|
|
12
|
+
});
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
const TRANSFORM = `
|
|
16
|
+
t.transform(__c, {
|
|
17
|
+
__a: __b
|
|
18
|
+
});
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
const {
|
|
22
|
+
Identifier,
|
|
23
|
+
isIdentifier,
|
|
24
|
+
} = types;
|
|
25
|
+
|
|
26
|
+
module.exports.report = () => 'Move require on top level';
|
|
27
|
+
|
|
28
|
+
module.exports.match = () => ({
|
|
29
|
+
[TEST]: ({__b}) => !isIdentifier(__b),
|
|
30
|
+
[TRANSFORM]: ({__b}) => !isIdentifier(__b),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
module.exports.replace = () => ({
|
|
34
|
+
[TEST]: (vars, path) => {
|
|
35
|
+
const name = declareRequire(vars, path);
|
|
36
|
+
const {__a} = vars;
|
|
37
|
+
const value = __a.value || __a.name;
|
|
38
|
+
|
|
39
|
+
return `
|
|
40
|
+
const test = require('@putout/test')(__dirname, {
|
|
41
|
+
'${value}': ${name},
|
|
42
|
+
});
|
|
43
|
+
`;
|
|
44
|
+
},
|
|
45
|
+
[TRANSFORM]: (vars, path) => {
|
|
46
|
+
const name = declareRequire(vars, path);
|
|
47
|
+
const {__a} = vars;
|
|
48
|
+
const value = __a.value || __a.name;
|
|
49
|
+
|
|
50
|
+
return `
|
|
51
|
+
t.transform(__c, {
|
|
52
|
+
'${value}': ${name},
|
|
53
|
+
});
|
|
54
|
+
`;
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const buildRequire = template(`const NAME = REQUIRE`);
|
|
59
|
+
|
|
60
|
+
function declareRequire({__a, __b}, path) {
|
|
61
|
+
const shortName = (__a.value || __a.name).split('/').pop();
|
|
62
|
+
const name = justCamelCase(shortName);
|
|
63
|
+
const requireNode = buildRequire({
|
|
64
|
+
NAME: Identifier(name),
|
|
65
|
+
REQUIRE: __b,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
if (path.scope.hasBinding(name))
|
|
69
|
+
return name;
|
|
70
|
+
|
|
71
|
+
const programPath = path.scope.getProgramParent().path;
|
|
72
|
+
programPath.node.body.unshift(requireNode);
|
|
73
|
+
|
|
74
|
+
return name;
|
|
75
|
+
}
|
|
76
|
+
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-putout",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.3.0",
|
|
4
4
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
5
5
|
"description": "putout plugin helps with plugins development",
|
|
6
|
-
"homepage": "
|
|
6
|
+
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-putout",
|
|
7
7
|
"main": "lib/index.js",
|
|
8
8
|
"release": false,
|
|
9
9
|
"tag": false,
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"url": "git://github.com/coderaiser/putout.git"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
|
+
"wisdom": "madrun wisdom",
|
|
16
17
|
"test": "madrun test",
|
|
17
18
|
"watch:test": "madrun watch:test",
|
|
18
19
|
"lint": "madrun lint",
|
|
@@ -24,6 +25,7 @@
|
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
27
|
"fullstore": "^3.0.0",
|
|
28
|
+
"just-camel-case": "^6.0.1",
|
|
27
29
|
"try-catch": "^3.0.0"
|
|
28
30
|
},
|
|
29
31
|
"keywords": [
|
|
@@ -33,11 +35,11 @@
|
|
|
33
35
|
"putout"
|
|
34
36
|
],
|
|
35
37
|
"devDependencies": {
|
|
36
|
-
"@putout/test": "^
|
|
38
|
+
"@putout/test": "^4.0.0",
|
|
37
39
|
"c8": "^7.5.0",
|
|
38
40
|
"eslint": "^8.0.1",
|
|
39
41
|
"eslint-plugin-node": "^11.0.0",
|
|
40
|
-
"eslint-plugin-putout": "^
|
|
42
|
+
"eslint-plugin-putout": "^12.0.0",
|
|
41
43
|
"lerna": "^4.0.0",
|
|
42
44
|
"madrun": "^8.0.1",
|
|
43
45
|
"nodemon": "^2.0.1"
|