@putout/plugin-putout 18.1.0 β†’ 18.2.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",
@@ -763,6 +765,26 @@ module.exports.traverse = ({push}) => ({
763
765
  });
764
766
  ```
765
767
 
768
+ ## add-track-file
769
+
770
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/faaba1ce41e6fd274bc82a8875a52bfa/b34a22fdf9080e6b2f06703760f629d83d69ff3d).
771
+
772
+ ### ❌ Example of incorrect code
773
+
774
+ ```js
775
+ export const scan = (root, {push, progress}) => {
776
+ trackFile();
777
+ };
778
+ ```
779
+
780
+ ### βœ… Example of correct code
781
+
782
+ ```js
783
+ export const scan = (root, {push, progress, trackFile}) => {
784
+ trackFile();
785
+ };
786
+ ```
787
+
766
788
  ## add-index-to-import
767
789
 
768
790
  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 +897,37 @@ module.exports.report = `'report' should be a 'function'`;
875
897
  module.exports.report = () => `'report' should be a 'function'`;
876
898
  ```
877
899
 
900
+ ## convert-progress-to-track
901
+
902
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/8736a0cf838a3660b0927e161e4fb06c/9f5c9f810babd4450898069d3d8dc28aceee1e2d).
903
+
904
+ ### ❌ Example of incorrect code
905
+
906
+ ```js
907
+ module.exports.scan = (root, {push, progress}) => {
908
+ const files = findFile(root, ['*']);
909
+ const n = files.length;
910
+
911
+ for (const [i, file] of files.entries()) {
912
+ push(file);
913
+ progress({
914
+ i,
915
+ n,
916
+ });
917
+ }
918
+ };
919
+ ```
920
+
921
+ ### βœ… Example of correct code
922
+
923
+ ```js
924
+ module.exports.scan = (root, {push, trackFile}) => {
925
+ for (const file of trackFile(root, ['*'])) {
926
+ push(file);
927
+ }
928
+ };
929
+ ```
930
+
878
931
  ## convert-get-rule-to-require
879
932
 
880
933
  - βœ… 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,10 @@
1
+ 'use strict';
2
+
3
+ const {operator} = require('putout');
4
+ const {addArgs} = operator;
5
+
6
+ module.exports = addArgs({
7
+ trackFile: ['{trackFile}', [
8
+ '(__a, __b) => __body',
9
+ ]],
10
+ });
@@ -0,0 +1,37 @@
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 false;
31
+
32
+ push({
33
+ path,
34
+ statement,
35
+ });
36
+ },
37
+ });
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 convertProgressToTrack = require('./convert-progress-to-track');
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': convertProgressToTrack,
93
97
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "18.1.0",
3
+ "version": "18.2.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",