@putout/plugin-putout 19.6.0 → 20.0.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
@@ -13,12 +13,10 @@ npm i @putout/plugin-putout -D
13
13
 
14
14
  ## Rules
15
15
 
16
- - ✅ [add-args](#add-args);
16
+ - ✅ [add-test-args](#add-test-args);
17
17
  - ✅ [add-await-to-progress](#add-await-to-progress);
18
18
  - ✅ [add-index-to-import](#add-index-to-import);
19
- - ✅ [add-push](#add-push);
20
- - ✅ [add-store](#add-store);
21
- - ✅ [add-path-store](#add-path-store);
19
+ - ✅ [add-traverse-args](#add-traverse-args);
22
20
  - ✅ [add-track-file](#add-track-file);
23
21
  - ✅ [apply-async-formatter](#apply-async-formatter);
24
22
  - ✅ [apply-create-test](#apply-create-test);
@@ -33,7 +31,7 @@ npm i @putout/plugin-putout -D
33
31
  - ✅ [apply-short-processors](#apply-short-processors);
34
32
  - ✅ [check-match](#check-match);
35
33
  - ✅ [check-replace-code](#check-replace-code);
36
- - ✅ [convert-add-argument-to-add-args](#convert-add-argument-to-add-args);
34
+ - ✅ [convert-add-argument-to-add-args](#convert-add-argument-to-add-test-args);
37
35
  - ✅ [convert-babel-types](#convert-babel-types);
38
36
  - ✅ [convert-destructuring-to-identifier](#convert-destructuring-to-identifier);
39
37
  - ✅ [convert-dirname-to-url](#convert-dirname-to-url);
@@ -81,10 +79,8 @@ npm i @putout/plugin-putout -D
81
79
  "putout/apply-short-processors": "on",
82
80
  "putout/apply-namespace-specifier": "on",
83
81
  "putout/apply-for-of-to-track-file": "on",
84
- "putout/add-args": "on",
85
- "putout/add-push": "on",
86
- "putout/add-store": "on",
87
- "putout/add-path-store": "on",
82
+ "putout/add-test-args": "on",
83
+ "putout/add-traverse-args": "on",
88
84
  "putout/add-track-file": "on",
89
85
  "putout/add-await-to-progress": "on",
90
86
  "putout/add-index-to-import": "on",
@@ -797,7 +793,7 @@ compare(a, 'const __a = __b');
797
793
  isIdentifier(a);
798
794
  ```
799
795
 
800
- ## add-args
796
+ ## add-test-args
801
797
 
802
798
  ### ❌ Example of incorrect code
803
799
 
@@ -815,7 +811,12 @@ test('', ({comparePlaces}) => {
815
811
  });
816
812
  ```
817
813
 
818
- ## add-push
814
+ ## add-traverse-args
815
+
816
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/b453bd78b8e9380da8b2f33dfb38b4e2/53b14f89eb88aa10c8e00ba1f0251976592e14ee).
817
+ Supported args:
818
+
819
+ - `push`:
819
820
 
820
821
  ### ❌ Example of incorrect code
821
822
 
@@ -837,9 +838,7 @@ module.exports.traverse = ({push}) => ({
837
838
  });
838
839
  ```
839
840
 
840
- ## add-store
841
-
842
- Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/b453bd78b8e9380da8b2f33dfb38b4e2/53b14f89eb88aa10c8e00ba1f0251976592e14ee).
841
+ - `store`
843
842
 
844
843
  ### ❌ Example of incorrect code
845
844
 
@@ -867,7 +866,7 @@ module.exports.traverse = ({store}) => ({
867
866
  });
868
867
  ```
869
868
 
870
- ## add-path-store
869
+ - `pathStore`:
871
870
 
872
871
  ### ❌ Example of incorrect code
873
872
 
@@ -9,21 +9,19 @@ const {
9
9
  Identifier,
10
10
  } = types;
11
11
 
12
- module.exports = function addArg(name) {
13
- return {
14
- report: createReport(name),
15
- fix: createFix(name),
16
- traverse: createTraverse(name),
17
- };
18
- };
12
+ const defaultNames = [
13
+ 'push',
14
+ 'store',
15
+ 'pathStore',
16
+ ];
19
17
 
20
- const createReport = (name) => () => `Add '${name}' argument to 'traverse'`;
18
+ module.exports.report = ({name}) => `Add '${name}' argument to 'traverse'`;
21
19
 
22
- const createFix = (mainName) => ({fn}) => {
20
+ module.exports.fix = ({name, fn}) => {
23
21
  const computed = false;
24
22
  const shorthand = true;
25
- const name = Identifier(mainName);
26
- const property = ObjectProperty(name, name, computed, shorthand);
23
+ const id = Identifier(name);
24
+ const property = ObjectProperty(id, id, computed, shorthand);
27
25
 
28
26
  if (!fn.params.length) {
29
27
  fn.params.push(ObjectPattern([property]));
@@ -33,8 +31,11 @@ const createFix = (mainName) => ({fn}) => {
33
31
  fn.params[0].properties.push(property);
34
32
  };
35
33
 
36
- const createTraverse = (name) => ({push}) => {
37
- const check = checkArgs(name, push);
34
+ module.exports.traverse = ({push, options}) => {
35
+ const {
36
+ names = defaultNames,
37
+ } = options;
38
+ const check = checkArgs(names, push);
38
39
 
39
40
  return {
40
41
  'export const traverse = (__args) => __': check,
@@ -54,34 +55,44 @@ const isArgExists = (mainName, fn) => {
54
55
  return false;
55
56
  };
56
57
 
57
- const checkArgs = (mainName, push) => (path) => {
58
+ const checkArgs = (names, push) => (path) => {
58
59
  const fn = parseFn(path);
59
60
 
60
- if (isArgExists(mainName, fn))
61
- return false;
62
-
63
61
  traverse(path, {
64
62
  ReferencedIdentifier(path) {
65
- if (path.node.name !== mainName)
63
+ const {name} = path.node;
64
+
65
+ if (!names.includes(name))
66
66
  return;
67
67
 
68
- if (isCallee(mainName, path))
68
+ if (isCallee(name, path))
69
+ return;
70
+
71
+ if (isArgExists(name, fn))
69
72
  return;
70
73
 
71
74
  push({
72
75
  path,
73
76
  fn,
77
+ name,
74
78
  });
75
79
  },
76
- [`${mainName}(__args)`]: (currentPath) => {
80
+ [`__a(__args)`]: (currentPath) => {
81
+ const {callee} = currentPath.node;
82
+ const {name} = callee;
83
+
84
+ if (!names.includes(name))
85
+ return;
86
+
77
87
  const bindings = currentPath.scope.getAllBindings();
78
88
 
79
- if (bindings[mainName])
89
+ if (bindings[name])
80
90
  return;
81
91
 
82
92
  push({
83
93
  path,
84
94
  fn,
95
+ name,
85
96
  });
86
97
  },
87
98
  });
package/lib/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const addStore = require('./add-store');
4
- const addPathStore = require('./add-path-store');
5
3
  const applyProcessorsDestructuring = require('./apply-processors-destructuring');
6
4
  const applyAsyncFormatter = require('./apply-async-formatter');
7
5
  const applyCreateTest = require('./apply-create-test');
@@ -36,8 +34,8 @@ const renameOperateToOperator = require('./rename-operate-to-operator');
36
34
  const replaceOperateWithOperator = require('./replace-operate-with-operator');
37
35
  const shortenImports = require('./shorten-imports');
38
36
  const declare = require('./declare');
39
- const addArgs = require('./add-args');
40
- const addPush = require('./add-push');
37
+ const addTestArgs = require('./add-test-args');
38
+ const addTraverseArgs = require('./add-traverse-args');
41
39
  const moveRequireOnTopLevel = require('./move-require-on-top-level');
42
40
  const includer = require('./includer');
43
41
  const createTest = require('./create-test');
@@ -53,8 +51,6 @@ const applyForOfToTrackFile = require('./apply-for-of-to-track-file');
53
51
  const removeUnusedGetPropertiesArgument = require('./remove-unused-get-properties-argument');
54
52
 
55
53
  module.exports.rules = {
56
- 'add-store': addStore,
57
- 'add-path-store': addPathStore,
58
54
  'apply-processors-destructuring': applyProcessorsDestructuring,
59
55
  'apply-async-formatter': applyAsyncFormatter,
60
56
  'apply-create-test': applyCreateTest,
@@ -88,8 +84,8 @@ module.exports.rules = {
88
84
  'replace-operate-with-operator': replaceOperateWithOperator,
89
85
  'shorten-imports': shortenImports,
90
86
  declare,
91
- 'add-args': addArgs,
92
- 'add-push': addPush,
87
+ 'add-test-args': addTestArgs,
88
+ 'add-traverse-args': addTraverseArgs,
93
89
  'move-require-on-top-level': moveRequireOnTopLevel,
94
90
  includer,
95
91
  'create-test': createTest,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "19.6.0",
3
+ "version": "20.0.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",
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- const addArg = require('../add-arg');
4
-
5
- module.exports = addArg('pathStore');
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- const addArg = require('../add-arg.js');
4
-
5
- module.exports = addArg('push');
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- const addArg = require('../add-arg');
4
-
5
- module.exports = addArg('store');
File without changes