@putout/plugin-putout 11.0.0 → 11.1.1

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
@@ -19,7 +19,9 @@ npm i @putout/plugin-putout -D
19
19
  "putout/apply-create-test": "on",
20
20
  "putout/apply-processors-destructuring": "on",
21
21
  "putout/apply-async-formatter": "on",
22
+ "putout/apply-remove": "on",
22
23
  "putout/add-args": "on",
24
+ "putout/add-push": "on",
23
25
  "putout/convert-putout-test-to-create-test": "on",
24
26
  "putout/convert-to-no-transform-code": "on",
25
27
  "putout/convert-replace-with": "on",
@@ -64,6 +66,30 @@ test('', async ({process}) => {
64
66
  });
65
67
  ```
66
68
 
69
+ ## apply-remove
70
+
71
+ Better to use [`remove(path)`](https://github.com/coderaiser/putout/tree/master/packages/operate#removepath) method of `operator`.
72
+ It helps to preserve comments.
73
+
74
+ ### ❌ Example of incorrect code
75
+
76
+ ```js
77
+ export const fix = (path) => {
78
+ path.remove();
79
+ };
80
+ ```
81
+
82
+ ### ✅ Example of correct code
83
+
84
+ ```js
85
+ import {operator} from 'putout';
86
+ const {remove} = operator;
87
+
88
+ export const fix = (path) => {
89
+ remove(path);
90
+ };
91
+ ```
92
+
67
93
  ## apply-async-formatter
68
94
 
69
95
  ### ❌ Example of incorrect code
@@ -102,7 +128,7 @@ const test = createTest({
102
128
  });
103
129
  ```
104
130
 
105
- ## convert-putout-test-to-create-test"
131
+ ## convert-putout-test-to-create-test
106
132
 
107
133
  Fixes results of [@putout/convert-commonjs-to-esm](https://github.com/coderaiser/putout/tree/master/packages/plugin-convert-commonjs-to-esm) work.
108
134
 
@@ -119,7 +145,7 @@ const test = putoutTest(__dirname, {
119
145
  ### ✅ Example of correct code
120
146
 
121
147
  ```js
122
- import createTest from '@putout/test';
148
+ import {createTest} from '@putout/test';
123
149
 
124
150
  const test = createTest(__dirname, {
125
151
  'remove-unused-variables': rmVars,
@@ -435,8 +461,32 @@ test('', ({comparePlaces}) => {
435
461
  });
436
462
  ```
437
463
 
464
+ ## add-push
465
+
466
+ ### ❌ Example of incorrect code
467
+
468
+ ```js
469
+ module.exports.traverse = () => ({
470
+ '__a.replace(/__b/g, __c)': (path) => {
471
+ push(path);
472
+ },
473
+ });
474
+ ```
475
+
476
+ ### ✅ Example of correct code
477
+
478
+ ```js
479
+ module.exports.traverse = ({push}) => ({
480
+ '__a.replace(/__b/g, __c)': (path) => {
481
+ push(path);
482
+ },
483
+ });
484
+ ```
485
+
438
486
  ## convert-add-argument-to-add-args
439
487
 
488
+ ### ❌ Example of incorrect code
489
+
440
490
  ```js
441
491
  const {operator} = require('putout');
442
492
  const {addArgument} = operator;
@@ -459,6 +509,8 @@ module.exports = addArgs({
459
509
 
460
510
  ## convert-dirname-to-url
461
511
 
512
+ ### ❌ Example of incorrect code
513
+
462
514
  ```js
463
515
  import {createTest} from '@putout/test';
464
516
  import plugin from '@putout/plugin-debugger';
@@ -483,11 +535,13 @@ const test = createTest(import.meta.url, {
483
535
 
484
536
  ## convert-url-to-dirname-
485
537
 
538
+ ### ❌ Example of incorrect code
539
+
486
540
  ```js
487
541
  const {createTest} = require('@putout/test');
488
542
  const plugin = require('@putout/plugin-debugger');
489
543
 
490
- const test = createTest(import.meta.url, {
544
+ const test = createTest(__dirname, {
491
545
  'remove-debugger': plugin,
492
546
  });
493
547
  ```
@@ -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
+ });
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ module.exports.report = () => `Use 'remove(path)' instead of 'path.remove()'`;
4
+
5
+ module.exports.replace = () => ({
6
+ 'path.remove()': 'remove(path)',
7
+ });
8
+
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ const {assign} = Object;
4
+
3
5
  module.exports.report = () => `Use 'createTest' instead of 'putoutTest'`;
4
6
 
5
7
  module.exports.filter = ({scope}) => !scope.bindings.createTest;
@@ -9,6 +11,14 @@ module.exports.include = () => [
9
11
  ];
10
12
 
11
13
  module.exports.fix = (path) => {
14
+ const [first] = path.node.specifiers;
15
+
16
+ assign(first, {
17
+ type: 'ImportSpecifier',
18
+ kind: 'value',
19
+ imported: first.local,
20
+ });
21
+
12
22
  path.scope.rename('putoutTest', 'createTest');
13
23
  };
14
24
 
@@ -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
+
@@ -10,9 +10,10 @@ module.exports = {
10
10
  declare: `const {declare} = operator`,
11
11
  isSimpleRegExp: `const {isSimpleRegExp} = operator`,
12
12
  getTemplateValues: `const {getTemplateValues} = operator`,
13
- addArgument: `const {addArgument} = operator`,
13
+ addArgs: `const {addArgs} = operator`,
14
14
  replaceWith: `const {replaceWith} = operator`,
15
15
  replaceWithMultiple: `const {replaceWithMultiple} = operator`,
16
+ remove: 'const {remove} = operator',
16
17
  isESM: `const {isESM} = operator`,
17
18
  getProperty: `const {getProperty} = operator`,
18
19
  getProperties: `const {getProperties} = operator`,
package/lib/index.js CHANGED
@@ -8,6 +8,7 @@ module.exports.rules = {
8
8
  ...getRule('apply-processors-destructuring'),
9
9
  ...getRule('apply-async-formatter'),
10
10
  ...getRule('apply-create-test'),
11
+ ...getRule('apply-remove'),
11
12
  ...getRule('convert-putout-test-to-create-test'),
12
13
  ...getRule('convert-to-no-transform-code'),
13
14
  ...getRule('convert-find-to-traverse'),
@@ -31,6 +32,7 @@ module.exports.rules = {
31
32
  ...getRule('check-replace-code'),
32
33
  ...getRule('declare'),
33
34
  ...getRule('add-args'),
35
+ ...getRule('add-push'),
34
36
  ...getRule('move-require-on-top-level'),
35
37
  ...getRule('includer'),
36
38
  };
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "11.0.0",
3
+ "version": "11.1.1",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
- "description": "putout plugin helps with plugins development",
6
+ "description": "🐊Putout plugin helps with plugins development",
7
7
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-putout#readme",
8
8
  "main": "lib/index.js",
9
9
  "release": false,
@@ -40,7 +40,7 @@
40
40
  "c8": "^7.5.0",
41
41
  "eslint": "^8.0.1",
42
42
  "eslint-plugin-node": "^11.0.0",
43
- "eslint-plugin-putout": "^14.0.0",
43
+ "eslint-plugin-putout": "^15.0.0",
44
44
  "lerna": "^4.0.0",
45
45
  "madrun": "^9.0.0",
46
46
  "montag": "^1.2.1",