@putout/plugin-putout 18.2.0 β†’ 18.4.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
@@ -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",
@@ -588,7 +589,10 @@ module.exports.replace = () => ({
588
589
 
589
590
  ## convert-traverse-to-scan
590
591
 
591
- Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/afe988c8e53ae70e50bf26512672f3cd/a6677d53b996e85880a4af18250c00e849322bbe).
592
+ Checkout in 🐊**Putout Editor**:
593
+
594
+ - [`Traverser`](https://putout.cloudcmd.io/#/gist/afe988c8e53ae70e50bf26512672f3cd/a6677d53b996e85880a4af18250c00e849322bbe);
595
+ - [`Replacer`](https://putout.cloudcmd.io/#/gist/2e89f498c88f3208beeb85dd01a9178e/ed975281c57f451fc1c3aaf187425a33499af71d);
592
596
 
593
597
  ### ❌ Example of incorrect code
594
598
 
@@ -765,6 +769,26 @@ module.exports.traverse = ({push}) => ({
765
769
  });
766
770
  ```
767
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
+
768
792
  ## add-track-file
769
793
 
770
794
  Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/faaba1ce41e6fd274bc82a8875a52bfa/b34a22fdf9080e6b2f06703760f629d83d69ff3d).
@@ -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,48 @@
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
+
12
+ const checkAwait = (vars, path) => !path.parentPath.isAwaitExpression();
13
+
14
+ module.exports.report = () => `Add 'await' to operator 'progress()'`;
15
+
16
+ module.exports.match = () => ({
17
+ 'progress(__args)': checkAwait,
18
+ 't.progress(__args)': checkAwait,
19
+ });
20
+
21
+ module.exports.replace = () => ({
22
+ 'test(__a, async (t, {progress}) => __body)': 'test(__a, async ({progress}) => __body)',
23
+ 'progress(__args)': addAwait,
24
+ 't.progress(__args)': addAwait,
25
+ });
26
+
27
+ function addAwait(vars, path) {
28
+ const next = path.parentPath.getNextSibling();
29
+
30
+ if (compare(next, 't.end()'))
31
+ remove(next);
32
+
33
+ const {params} = path.scope.block;
34
+ const [first] = params;
35
+
36
+ if (first.name === 't') {
37
+ const id = Identifier('progress');
38
+
39
+ path.scope.block.params = [
40
+ ObjectPattern([
41
+ ObjectProperty(id, id, false, true),
42
+ ]),
43
+ ];
44
+ }
45
+
46
+ path.scope.block.async = true;
47
+ return 'await progress(__args)';
48
+ }
@@ -27,7 +27,16 @@ module.exports.traverse = ({push}) => ({
27
27
  const statement = path.find(isForOfStatement);
28
28
 
29
29
  if (!statement)
30
- return false;
30
+ return;
31
+
32
+ const forOfCount = statement
33
+ .parentPath
34
+ .get('body')
35
+ .filter(isForOfStatement)
36
+ .length;
37
+
38
+ if (forOfCount > 1)
39
+ return;
31
40
 
32
41
  push({
33
42
  path,
@@ -33,7 +33,12 @@ module.exports.fix = ({path, pathProperty}) => {
33
33
  replaceWith(path.parentPath, path.get('value.body'));
34
34
  path.parentPath.parentPath.node.params.unshift(Identifier('path'));
35
35
 
36
- const {left} = path.parentPath.parentPath.parentPath.node;
36
+ const assignmentPath = path.parentPath.parentPath.parentPath;
37
+
38
+ if (!assignmentPath.isAssignmentExpression())
39
+ return;
40
+
41
+ const {left} = assignmentPath.node;
37
42
 
38
43
  left.property.name = 'scan';
39
44
  return;
@@ -84,7 +89,6 @@ module.exports.traverse = ({push}) => ({
84
89
  path,
85
90
  });
86
91
  },
87
- '__.map(push)'() {},
88
92
  'push(__a)'(path) {
89
93
  const __aPath = path.get('arguments.0');
90
94
 
package/lib/index.js CHANGED
@@ -45,7 +45,8 @@ const addIndexToImport = require('./add-index-to-import');
45
45
  const applyRename = require('./apply-rename');
46
46
  const applyShortProcessors = require('./apply-short-processors');
47
47
  const addTrackFile = require('./add-track-file');
48
- const convertProgressToTrack = require('./convert-progress-to-track');
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,
@@ -93,5 +94,6 @@ module.exports.rules = {
93
94
  'apply-short-processors': applyShortProcessors,
94
95
  'convert-traverse-to-scan': convertTraverseToScan,
95
96
  'add-track-file': addTrackFile,
96
- 'convert-progress-to-track': convertProgressToTrack,
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.2.0",
3
+ "version": "18.4.0",
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",