@putout/plugin-putout 11.0.1 → 11.1.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
@@ -20,6 +20,7 @@ npm i @putout/plugin-putout -D
20
20
  "putout/apply-processors-destructuring": "on",
21
21
  "putout/apply-async-formatter": "on",
22
22
  "putout/add-args": "on",
23
+ "putout/add-push": "on",
23
24
  "putout/convert-putout-test-to-create-test": "on",
24
25
  "putout/convert-to-no-transform-code": "on",
25
26
  "putout/convert-replace-with": "on",
@@ -435,6 +436,28 @@ test('', ({comparePlaces}) => {
435
436
  });
436
437
  ```
437
438
 
439
+ ## add-push
440
+
441
+ ### ❌ Example of incorrect code
442
+
443
+ ```js
444
+ module.exports.traverse = () => ({
445
+ '__a.replace(/__b/g, __c)': (path) => {
446
+ push(path);
447
+ },
448
+ });
449
+ ```
450
+
451
+ ### ✅ Example of correct code
452
+
453
+ ```js
454
+ module.exports.traverse = ({push}) => ({
455
+ '__a.replace(/__b/g, __c)': (path) => {
456
+ push(path);
457
+ },
458
+ });
459
+ ```
460
+
438
461
  ## convert-add-argument-to-add-args
439
462
 
440
463
  ```js
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ const {
4
+ types,
5
+ operator,
6
+ } = require('putout');
7
+
8
+ const {traverse} = operator;
9
+
10
+ const {
11
+ ObjectProperty,
12
+ ObjectPattern,
13
+ Identifier,
14
+ } = types;
15
+
16
+ module.exports.report = () => `Add 'push' argument to 'traverse'`;
17
+
18
+ module.exports.fix = (path) => {
19
+ const computed = false;
20
+ const shorthand = true;
21
+ const name = Identifier('push');
22
+
23
+ path.node.right.params.push(ObjectPattern([
24
+ ObjectProperty(name, name, computed, shorthand),
25
+ ]));
26
+ };
27
+
28
+ module.exports.traverse = ({push}) => ({
29
+ 'module.exports.traverse = (__args) => __': (traversePath) => {
30
+ const paramsPaths = traversePath.get('right.params');
31
+
32
+ if (paramsPaths.length)
33
+ return;
34
+
35
+ traverse(traversePath, {
36
+ 'push(__)': () => {
37
+ push(traversePath);
38
+ },
39
+ });
40
+ },
41
+ });
@@ -1,7 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  const {operator} = require('putout');
4
- const {contains} = operator;
4
+ const {
5
+ contains,
6
+ traverse,
7
+ } = operator;
5
8
 
6
9
  module.exports.report = () => 'Replacer should be used instead of Traverser (https://git.io/JqcMn)';
7
10
 
@@ -15,6 +18,9 @@ module.exports.match = () => ({
15
18
  if (withFix)
16
19
  return false;
17
20
 
21
+ if (hasPushCall(path))
22
+ return false;
23
+
18
24
  if (!__args.length)
19
25
  return true;
20
26
 
@@ -22,6 +28,9 @@ module.exports.match = () => ({
22
28
  'push',
23
29
  ]);
24
30
 
31
+ if (withPush)
32
+ return false;
33
+
25
34
  return !withPush;
26
35
  },
27
36
  });
@@ -30,3 +39,16 @@ module.exports.replace = () => ({
30
39
  'module.exports.traverse = (__args) => __a': 'module.exports.replace = (__args) => __a',
31
40
  });
32
41
 
42
+ function hasPushCall(path) {
43
+ let is = false;
44
+
45
+ traverse(path, {
46
+ 'push(__a)': (path) => {
47
+ is = true;
48
+ path.stop();
49
+ },
50
+ });
51
+
52
+ return is;
53
+ }
54
+
package/lib/index.js CHANGED
@@ -31,6 +31,7 @@ module.exports.rules = {
31
31
  ...getRule('check-replace-code'),
32
32
  ...getRule('declare'),
33
33
  ...getRule('add-args'),
34
+ ...getRule('add-push'),
34
35
  ...getRule('move-require-on-top-level'),
35
36
  ...getRule('includer'),
36
37
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "11.0.1",
3
+ "version": "11.1.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",