@putout/plugin-putout 18.3.0 β 18.4.1
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
|
@@ -29,6 +29,7 @@ npm i @putout/plugin-putout -D
|
|
|
29
29
|
"putout/add-args": "on",
|
|
30
30
|
"putout/add-push": "on",
|
|
31
31
|
"putout/add-track-file": "on",
|
|
32
|
+
"putout/add-await-to-progress": "on",
|
|
32
33
|
"putout/add-index-to-import": "on",
|
|
33
34
|
"putout/check-match": "on",
|
|
34
35
|
"putout/check-replace-code": "on",
|
|
@@ -768,6 +769,26 @@ module.exports.traverse = ({push}) => ({
|
|
|
768
769
|
});
|
|
769
770
|
```
|
|
770
771
|
|
|
772
|
+
## add-await-to-progress
|
|
773
|
+
|
|
774
|
+
Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/978d70945edfa369390ea059654ff04d/89225c04039b9c0e9057aad34852c9428264f119).
|
|
775
|
+
|
|
776
|
+
### β Example of incorrect code
|
|
777
|
+
|
|
778
|
+
```js
|
|
779
|
+
test('', ({progress}) => {
|
|
780
|
+
progress();
|
|
781
|
+
});
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
### β
Example of correct code
|
|
785
|
+
|
|
786
|
+
```js
|
|
787
|
+
test('', async ({progress}) => {
|
|
788
|
+
await progress();
|
|
789
|
+
});
|
|
790
|
+
```
|
|
791
|
+
|
|
771
792
|
## add-track-file
|
|
772
793
|
|
|
773
794
|
Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/faaba1ce41e6fd274bc82a8875a52bfa/b34a22fdf9080e6b2f06703760f629d83d69ff3d).
|
package/lib/add-args/index.js
CHANGED
|
@@ -19,4 +19,9 @@ module.exports = addArgs({
|
|
|
19
19
|
'test.skip("__a", async (__args) => __body)',
|
|
20
20
|
'test.only("__a", async (__args) => __body)',
|
|
21
21
|
]],
|
|
22
|
+
progress: ['{progress}', [
|
|
23
|
+
'test("__a", async (__args) => __body)',
|
|
24
|
+
'test.skip("__a", async (__args) => __body)',
|
|
25
|
+
'test.only("__a", async (__args) => __body)',
|
|
26
|
+
]],
|
|
22
27
|
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types, operator} = require('putout');
|
|
4
|
+
const {
|
|
5
|
+
Identifier,
|
|
6
|
+
ObjectPattern,
|
|
7
|
+
ObjectProperty,
|
|
8
|
+
} = types;
|
|
9
|
+
|
|
10
|
+
const {remove, compare} = operator;
|
|
11
|
+
const isInsideTest = ({parentPath}) => compare(parentPath, 'test(__a, __b)');
|
|
12
|
+
|
|
13
|
+
const checkAwait = (vars, path) => {
|
|
14
|
+
if (!path.find(isInsideTest))
|
|
15
|
+
return false;
|
|
16
|
+
|
|
17
|
+
return !path.parentPath.isAwaitExpression();
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
module.exports.report = () => `Add 'await' to operator 'progress()'`;
|
|
21
|
+
|
|
22
|
+
module.exports.match = () => ({
|
|
23
|
+
'progress(__args)': checkAwait,
|
|
24
|
+
't.progress(__args)': checkAwait,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
module.exports.replace = () => ({
|
|
28
|
+
'test(__a, async (t, {progress}) => __body)': 'test(__a, async ({progress}) => __body)',
|
|
29
|
+
'progress(__args)': addAwait,
|
|
30
|
+
't.progress(__args)': addAwait,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
function addAwait(vars, path) {
|
|
34
|
+
const next = path.parentPath.getNextSibling();
|
|
35
|
+
|
|
36
|
+
if (compare(next, 't.end()'))
|
|
37
|
+
remove(next);
|
|
38
|
+
|
|
39
|
+
const {params} = path.scope.block;
|
|
40
|
+
const [first] = params;
|
|
41
|
+
|
|
42
|
+
if (first.name === 't') {
|
|
43
|
+
const id = Identifier('progress');
|
|
44
|
+
|
|
45
|
+
path.scope.block.params = [
|
|
46
|
+
ObjectPattern([
|
|
47
|
+
ObjectProperty(id, id, false, true),
|
|
48
|
+
]),
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
path.scope.block.async = true;
|
|
53
|
+
return 'await progress(__args)';
|
|
54
|
+
}
|
|
@@ -29,7 +29,11 @@ module.exports.traverse = ({push}) => ({
|
|
|
29
29
|
if (!statement)
|
|
30
30
|
return;
|
|
31
31
|
|
|
32
|
-
const forOfCount = statement
|
|
32
|
+
const forOfCount = statement
|
|
33
|
+
.parentPath
|
|
34
|
+
.get('body')
|
|
35
|
+
.filter(isForOfStatement)
|
|
36
|
+
.length;
|
|
33
37
|
|
|
34
38
|
if (forOfCount > 1)
|
|
35
39
|
return;
|
package/lib/index.js
CHANGED
|
@@ -46,6 +46,7 @@ const applyRename = require('./apply-rename');
|
|
|
46
46
|
const applyShortProcessors = require('./apply-short-processors');
|
|
47
47
|
const addTrackFile = require('./add-track-file');
|
|
48
48
|
const convertProgressToTrackFile = require('./convert-progress-to-track-file');
|
|
49
|
+
const addAwaitToProgress = require('./add-await-to-progress');
|
|
49
50
|
|
|
50
51
|
module.exports.rules = {
|
|
51
52
|
'apply-processors-destructuring': applyProcessorsDestructuring,
|
|
@@ -94,4 +95,5 @@ module.exports.rules = {
|
|
|
94
95
|
'convert-traverse-to-scan': convertTraverseToScan,
|
|
95
96
|
'add-track-file': addTrackFile,
|
|
96
97
|
'convert-progress-to-track-file': convertProgressToTrackFile,
|
|
98
|
+
'add-await-to-progress': addAwaitToProgress,
|
|
97
99
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-putout",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.4.1",
|
|
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",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"putout"
|
|
38
38
|
],
|
|
39
39
|
"devDependencies": {
|
|
40
|
+
"@putout/plugin-tape": "*",
|
|
40
41
|
"@putout/test": "^8.0.0",
|
|
41
42
|
"c8": "^8.0.0",
|
|
42
43
|
"eslint": "^8.0.1",
|