@putout/plugin-putout 18.1.0 β 18.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
CHANGED
|
@@ -28,6 +28,7 @@ npm i @putout/plugin-putout -D
|
|
|
28
28
|
"putout/apply-namaspace-specifier": "on",
|
|
29
29
|
"putout/add-args": "on",
|
|
30
30
|
"putout/add-push": "on",
|
|
31
|
+
"putout/add-track-file": "on",
|
|
31
32
|
"putout/add-index-to-import": "on",
|
|
32
33
|
"putout/check-match": "on",
|
|
33
34
|
"putout/check-replace-code": "on",
|
|
@@ -51,6 +52,7 @@ npm i @putout/plugin-putout -D
|
|
|
51
52
|
"putout/convert-url-to-dirname": "on",
|
|
52
53
|
"putout/convert-report-to-function": "on",
|
|
53
54
|
"putout/convert-get-rule-to-require": "on",
|
|
55
|
+
"putout/convert-progress-to-track-file": "on",
|
|
54
56
|
"putout/create-test": "on",
|
|
55
57
|
"putout/shorten-imports": "on",
|
|
56
58
|
"putout/declare": "on",
|
|
@@ -586,7 +588,10 @@ module.exports.replace = () => ({
|
|
|
586
588
|
|
|
587
589
|
## convert-traverse-to-scan
|
|
588
590
|
|
|
589
|
-
Checkout in
|
|
591
|
+
Checkout in π**Putout Editor**:
|
|
592
|
+
|
|
593
|
+
- [`Traverser`](https://putout.cloudcmd.io/#/gist/afe988c8e53ae70e50bf26512672f3cd/a6677d53b996e85880a4af18250c00e849322bbe);
|
|
594
|
+
- [`Replacer`](https://putout.cloudcmd.io/#/gist/2e89f498c88f3208beeb85dd01a9178e/ed975281c57f451fc1c3aaf187425a33499af71d);
|
|
590
595
|
|
|
591
596
|
### β Example of incorrect code
|
|
592
597
|
|
|
@@ -763,6 +768,26 @@ module.exports.traverse = ({push}) => ({
|
|
|
763
768
|
});
|
|
764
769
|
```
|
|
765
770
|
|
|
771
|
+
## add-track-file
|
|
772
|
+
|
|
773
|
+
Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/faaba1ce41e6fd274bc82a8875a52bfa/b34a22fdf9080e6b2f06703760f629d83d69ff3d).
|
|
774
|
+
|
|
775
|
+
### β Example of incorrect code
|
|
776
|
+
|
|
777
|
+
```js
|
|
778
|
+
export const scan = (root, {push, progress}) => {
|
|
779
|
+
trackFile();
|
|
780
|
+
};
|
|
781
|
+
```
|
|
782
|
+
|
|
783
|
+
### β
Example of correct code
|
|
784
|
+
|
|
785
|
+
```js
|
|
786
|
+
export const scan = (root, {push, progress, trackFile}) => {
|
|
787
|
+
trackFile();
|
|
788
|
+
};
|
|
789
|
+
```
|
|
790
|
+
|
|
766
791
|
## add-index-to-import
|
|
767
792
|
|
|
768
793
|
ESM doesn't add `index.js`, so it can be left after [`@putout/plugin-convert-esm-to-commonjs`](https://github.com/coderaiser/putout/blob/master/packages/plugin-convert-esm-to-commonjs#readme).
|
|
@@ -875,6 +900,37 @@ module.exports.report = `'report' should be a 'function'`;
|
|
|
875
900
|
module.exports.report = () => `'report' should be a 'function'`;
|
|
876
901
|
```
|
|
877
902
|
|
|
903
|
+
## convert-progress-to-track
|
|
904
|
+
|
|
905
|
+
Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/8736a0cf838a3660b0927e161e4fb06c/9f5c9f810babd4450898069d3d8dc28aceee1e2d).
|
|
906
|
+
|
|
907
|
+
### β Example of incorrect code
|
|
908
|
+
|
|
909
|
+
```js
|
|
910
|
+
module.exports.scan = (root, {push, progress}) => {
|
|
911
|
+
const files = findFile(root, ['*']);
|
|
912
|
+
const n = files.length;
|
|
913
|
+
|
|
914
|
+
for (const [i, file] of files.entries()) {
|
|
915
|
+
push(file);
|
|
916
|
+
progress({
|
|
917
|
+
i,
|
|
918
|
+
n,
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
```
|
|
923
|
+
|
|
924
|
+
### β
Example of correct code
|
|
925
|
+
|
|
926
|
+
```js
|
|
927
|
+
module.exports.scan = (root, {push, trackFile}) => {
|
|
928
|
+
for (const file of trackFile(root, ['*'])) {
|
|
929
|
+
push(file);
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
```
|
|
933
|
+
|
|
878
934
|
## convert-get-rule-to-require
|
|
879
935
|
|
|
880
936
|
- β
import [Nested plugins](https://github.com/coderaiser/putout/tree/master/packages/engine-loader#nested-plugin) in [**Deno** and **Browser**](https://github.com/putoutjs/bundle/);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {operator, types} = require('putout');
|
|
4
|
+
|
|
5
|
+
const {isForOfStatement} = types;
|
|
6
|
+
const {remove, replaceWith} = operator;
|
|
7
|
+
|
|
8
|
+
module.exports.report = () => `Convert 'progress()' to 'trackFile()'`;
|
|
9
|
+
|
|
10
|
+
module.exports.fix = ({path, statement}) => {
|
|
11
|
+
const {name} = statement.node.right.callee.object;
|
|
12
|
+
const nameBinding = path.scope.getAllBindings()[name];
|
|
13
|
+
const {init} = nameBinding.path.node;
|
|
14
|
+
|
|
15
|
+
init.callee.name = 'trackFile';
|
|
16
|
+
|
|
17
|
+
replaceWith(statement.get('right'), init);
|
|
18
|
+
const id = statement.get('left.declarations.0.id');
|
|
19
|
+
|
|
20
|
+
replaceWith(id, id.get('elements.1'));
|
|
21
|
+
|
|
22
|
+
remove(path);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
module.exports.traverse = ({push}) => ({
|
|
26
|
+
'progress(__args)': (path) => {
|
|
27
|
+
const statement = path.find(isForOfStatement);
|
|
28
|
+
|
|
29
|
+
if (!statement)
|
|
30
|
+
return;
|
|
31
|
+
|
|
32
|
+
const forOfCount = statement.parentPath.get('body').filter(isForOfStatement).length;
|
|
33
|
+
|
|
34
|
+
if (forOfCount > 1)
|
|
35
|
+
return;
|
|
36
|
+
|
|
37
|
+
push({
|
|
38
|
+
path,
|
|
39
|
+
statement,
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
});
|
|
@@ -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
|
|
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
|
@@ -44,6 +44,8 @@ const convertGetRuleToRequire = require('./convert-get-rule-to-require');
|
|
|
44
44
|
const addIndexToImport = require('./add-index-to-import');
|
|
45
45
|
const applyRename = require('./apply-rename');
|
|
46
46
|
const applyShortProcessors = require('./apply-short-processors');
|
|
47
|
+
const addTrackFile = require('./add-track-file');
|
|
48
|
+
const convertProgressToTrackFile = require('./convert-progress-to-track-file');
|
|
47
49
|
|
|
48
50
|
module.exports.rules = {
|
|
49
51
|
'apply-processors-destructuring': applyProcessorsDestructuring,
|
|
@@ -90,4 +92,6 @@ module.exports.rules = {
|
|
|
90
92
|
'apply-rename': applyRename,
|
|
91
93
|
'apply-short-processors': applyShortProcessors,
|
|
92
94
|
'convert-traverse-to-scan': convertTraverseToScan,
|
|
95
|
+
'add-track-file': addTrackFile,
|
|
96
|
+
'convert-progress-to-track-file': convertProgressToTrackFile,
|
|
93
97
|
};
|
package/package.json
CHANGED