@putout/plugin-putout 12.1.0 → 12.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.
Files changed (37) hide show
  1. package/README.md +55 -26
  2. package/lib/add-args/index.js +3 -9
  3. package/lib/apply-async-formatter/index.js +0 -1
  4. package/lib/apply-create-test/index.js +0 -1
  5. package/lib/apply-declare/index.js +0 -1
  6. package/lib/apply-processors-destructuring/index.js +0 -1
  7. package/lib/apply-remove/index.js +0 -1
  8. package/lib/check-replace-code/generate-code.js +11 -4
  9. package/lib/check-replace-code/index.js +12 -8
  10. package/lib/convert-add-argument-to-add-args/index.js +0 -1
  11. package/lib/convert-babel-types/index.js +6 -6
  12. package/lib/convert-dirname-to-url/index.js +0 -1
  13. package/lib/convert-find-to-traverse/index.js +9 -6
  14. package/lib/convert-match-to-function/index.js +0 -1
  15. package/lib/convert-method-to-property/index.js +4 -2
  16. package/lib/convert-node-to-path-in-get-template-values/index.js +0 -2
  17. package/lib/convert-number-to-numeric/index.js +0 -1
  18. package/lib/convert-process-to-find/index.js +0 -1
  19. package/lib/convert-putout-test-to-create-test/index.js +0 -2
  20. package/lib/convert-replace-to-function/index.js +0 -1
  21. package/lib/convert-replace-with/index.js +5 -5
  22. package/lib/convert-replace-with-multiple/index.js +6 -6
  23. package/lib/convert-to-no-transform-code/index.js +4 -2
  24. package/lib/convert-traverse-to-include/index.js +5 -4
  25. package/lib/convert-traverse-to-replace/index.js +2 -1
  26. package/lib/convert-url-to-dirname/index.js +0 -1
  27. package/lib/create-test/index.js +26 -8
  28. package/lib/declare/index.js +0 -1
  29. package/lib/declare/operator.js +0 -1
  30. package/lib/declare/types.json +1 -1
  31. package/lib/includer/index.js +0 -2
  32. package/lib/index.js +0 -1
  33. package/lib/move-require-on-top-level/index.js +8 -3
  34. package/lib/replace-operate-with-operator/index.js +0 -1
  35. package/lib/replace-test-message/index.js +10 -4
  36. package/lib/shorten-imports/index.js +0 -1
  37. package/package.json +1 -1
package/README.md CHANGED
@@ -78,7 +78,8 @@ It helps to preserve comments.
78
78
  ### ❌ Example of incorrect code
79
79
 
80
80
  ```js
81
- export const fix = (path) => {
81
+ export
82
+ const fix = (path) => {
82
83
  path.remove();
83
84
  };
84
85
  ```
@@ -87,6 +88,7 @@ export const fix = (path) => {
87
88
 
88
89
  ```js
89
90
  import {operator} from 'putout';
91
+
90
92
  const {remove} = operator;
91
93
 
92
94
  export const fix = (path) => {
@@ -153,6 +155,7 @@ const test = require('@putout/test')({
153
155
 
154
156
  ```js
155
157
  const {createTest} = require('@putout/test');
158
+
156
159
  const test = createTest({
157
160
  'remove-debugger': plugin,
158
161
  });
@@ -166,7 +169,9 @@ Add properties to `createTest` options, here is exmample of `.putout.json`:
166
169
  {
167
170
  "rules": {
168
171
  "putout/create-test": ["on", {
169
- "add": ["printer", "putout"]
172
+ "add": [
173
+ ["printer", "putout"]
174
+ ]
170
175
  }]
171
176
  }
172
177
  }
@@ -285,7 +290,9 @@ module.exports.fix = (path) => {
285
290
 
286
291
  ```js
287
292
  module.exports.fix = (path) => {
288
- path.replaceWithMultiple([Identifier('hello')]);
293
+ path.replaceWithMultiple([
294
+ Identifier('hello'),
295
+ ]);
289
296
  };
290
297
  ```
291
298
 
@@ -295,7 +302,9 @@ module.exports.fix = (path) => {
295
302
  const {replaceWithMultiple} = require('putout').operator;
296
303
 
297
304
  module.exports.fix = (path) => {
298
- replaceWithMultiple(path, [Identifier('hello')]);
305
+ replaceWithMultiple(path, [
306
+ Identifier('hello'),
307
+ ]);
299
308
  };
300
309
  ```
301
310
 
@@ -365,10 +374,8 @@ const {
365
374
 
366
375
  ```js
367
376
  module.exports.replace = () => ({
368
- 'const __a = __b': ({}) => {
369
- },
370
- 'const __c = __d': ({}, path) => {
371
- },
377
+ 'const __a = __b': ({}) => {},
378
+ 'const __c = __d': ({}, path) => {},
372
379
  });
373
380
  ```
374
381
 
@@ -376,10 +383,8 @@ module.exports.replace = () => ({
376
383
 
377
384
  ```js
378
385
  module.exports.replace = () => ({
379
- 'const __a = __b': (vars) => {
380
- },
381
- 'const __c = __d': (vars, path) => {
382
- },
386
+ 'const __a = __b': (vars) => {},
387
+ 'const __c = __d': (vars, path) => {},
383
388
  });
384
389
  ```
385
390
 
@@ -474,8 +479,7 @@ module.exports.merge = (processedSource, list) => '';
474
479
 
475
480
  ```js
476
481
  module.exports.match = () => ({
477
- 'module.exports.traverse = __a'({}, path) {
478
- },
482
+ 'module.exports.traverse = __a'({}, path) {},
479
483
  });
480
484
  ```
481
485
 
@@ -483,8 +487,7 @@ module.exports.match = () => ({
483
487
 
484
488
  ```js
485
489
  module.exports.match = () => ({
486
- 'module.exports.traverse = __a': ({}, path) => {
487
- },
490
+ 'module.exports.traverse = __a': ({}, path) => {},
488
491
  });
489
492
  ```
490
493
 
@@ -518,7 +521,11 @@ isIdentifier(a);
518
521
  ### ✅ Example of correct code
519
522
 
520
523
  ```js
521
- const {operator, types} = require('putout');
524
+ const {
525
+ operator,
526
+ types,
527
+ } = require('putout');
528
+
522
529
  const {compare} = operator;
523
530
  const {isIdentifier} = types;
524
531
 
@@ -598,6 +605,7 @@ module.exports = addArgs({
598
605
  import {createTest} from '@putout/test';
599
606
  import plugin from '@putout/plugin-debugger';
600
607
  import {createSimport} from 'simport';
608
+
601
609
  const {__dirname} = createSimport(import.meta.url);
602
610
 
603
611
  const test = createTest(__dirname, {
@@ -675,6 +683,7 @@ test('remove debugger: report', (t) => {
675
683
 
676
684
  ```js
677
685
  const removeDebugger = require('..');
686
+
678
687
  const test = require('@putout/test')(__dirname, {
679
688
  'remove-debugger': removeDebugger,
680
689
  });
@@ -683,6 +692,7 @@ test('remove debugger: report', (t) => {
683
692
  const test = require('@putout/test')(__dirname, {
684
693
  'remove-debugger': removeDebugger,
685
694
  });
695
+
686
696
  t.end();
687
697
  });
688
698
  ```
@@ -694,25 +704,44 @@ test('remove debugger: report', (t) => {
694
704
  ```js
695
705
  module.exports.include = () => 'cons __a = __b';
696
706
  module.exports.exclude = () => 'var __a = __b';
697
-
698
707
  module.exports.include = 'cons __a = __b';
699
708
  module.exports.exclude = 'var __a = __b';
700
709
 
701
- module.exports.include = ['cons __a = __b'];
702
- module.exports.exclude = ['var __a = __b'];
710
+ module.exports.include = [
711
+ 'cons __a = __b',
712
+ ];
713
+
714
+ module.exports.exclude = [
715
+ 'var __a = __b',
716
+ ];
703
717
  ```
704
718
 
705
719
  ### ✅ Example of correct code
706
720
 
707
721
  ```js
708
- module.exports.include = () => ['cons __a = __b'];
709
- module.exports.exclude = () => ['var __a = __b'];
722
+ module.exports.include = () => [
723
+ 'cons __a = __b',
724
+ ];
710
725
 
711
- module.exports.include = () => ['cons __a = __b'];
712
- module.exports.exclude = () => ['var __a = __b'];
726
+ module.exports.exclude = () => [
727
+ 'var __a = __b',
728
+ ];
713
729
 
714
- module.exports.include = () => ['cons __a = __b'];
715
- module.exports.exclude = () => ['var __a = __b'];
730
+ module.exports.include = () => [
731
+ 'cons __a = __b',
732
+ ];
733
+
734
+ module.exports.exclude = () => [
735
+ 'var __a = __b',
736
+ ];
737
+
738
+ module.exports.include = () => [
739
+ 'cons __a = __b',
740
+ ];
741
+
742
+ module.exports.exclude = () => [
743
+ 'var __a = __b',
744
+ ];
716
745
  ```
717
746
 
718
747
  ## replace-test-message
@@ -8,21 +8,15 @@ module.exports = addArgs({
8
8
  'test("__a", async (__args) => __body)',
9
9
  'test.skip("__a", async (__args) => __body)',
10
10
  'test.only("__a", async (__args) => __body)',
11
- ],
12
- ],
13
-
11
+ ]],
14
12
  process: ['{process}', [
15
13
  'test("__a", async (__args) => __body)',
16
14
  'test.skip("__a", async (__args) => __body)',
17
15
  'test.only("__a", async (__args) => __body)',
18
- ],
19
- ],
20
-
16
+ ]],
21
17
  noProcess: ['{noProcess}', [
22
18
  'test("__a", async (__args) => __body)',
23
19
  'test.skip("__a", async (__args) => __body)',
24
20
  'test.only("__a", async (__args) => __body)',
25
- ],
26
- ],
21
+ ]],
27
22
  });
28
-
@@ -44,4 +44,3 @@ const create = (name) => (vars, path) => {
44
44
 
45
45
  return `await ${name}(__args)`;
46
46
  };
47
-
@@ -5,4 +5,3 @@ module.exports.report = () => `Apply 'createTest'`;
5
5
  module.exports.replace = () => ({
6
6
  'require("@putout/test")(__dirname, __a)': `createTest(__dirname, __a)`,
7
7
  });
8
-
@@ -5,4 +5,3 @@ module.exports.report = () => `Use 'Declarator' instead of 'operator.declare()'`
5
5
  module.exports.replace = () => ({
6
6
  'module.exports = declare(__a)': 'module.exports.declare = () => __a',
7
7
  });
8
-
@@ -6,7 +6,6 @@ module.exports.replace = () => ({
6
6
  'async (t) => {await t.process(__args)}': 'async ({process}) => {await process(__args)}',
7
7
  'async (t) => {await t.noProcess(__args)}': 'async ({noProcess}) => {await noProcess(__args)}',
8
8
  'async (t) => {await t.comparePlaces(__args)}': 'async ({comparePlaces}) => {await comparePlaces(__args)}',
9
-
10
9
  'async (t) => {await t.process(__args); t.end();}': 'async ({process}) => {await process(__args)}',
11
10
  'async (t) => {await t.noProcess(__args); t.end();}': 'async ({noProcess}) => {await noProcess(__args)}',
12
11
  'async (t) => {await t.comparePlaces(__args); t.end();}': 'async ({comparePlaces}) => {await comparePlaces(__args)}',
@@ -5,4 +5,3 @@ module.exports.report = () => `Use 'remove(path)' instead of 'path.remove()'`;
5
5
  module.exports.replace = () => ({
6
6
  'path.remove()': 'remove(path)',
7
7
  });
8
-
@@ -2,11 +2,15 @@
2
2
 
3
3
  const putout = require('putout');
4
4
  const tryCatch = require('try-catch');
5
-
6
5
  const noop = () => {};
7
6
 
8
- const {types, operator} = putout;
7
+ const {
8
+ types,
9
+ operator,
10
+ } = putout;
11
+
9
12
  const {replaceWith} = operator;
13
+
10
14
  const {
11
15
  ArrayPattern,
12
16
  ObjectPattern,
@@ -16,6 +20,7 @@ const {
16
20
 
17
21
  module.exports = (rootPath, key) => {
18
22
  const getVar = createVarStore(rootPath);
23
+
19
24
  const [transformError, result] = tryCatch(putout, key, {
20
25
  fix: true,
21
26
  isTS: true,
@@ -75,7 +80,10 @@ module.exports = (rootPath, key) => {
75
80
  ],
76
81
  });
77
82
 
78
- return [transformError, result?.code];
83
+ return [
84
+ transformError,
85
+ result?.code,
86
+ ];
79
87
  };
80
88
 
81
89
  function createVarStore(path) {
@@ -102,4 +110,3 @@ function objectify(path) {
102
110
  if (isAssign && parentPath.get('right') === path)
103
111
  return replaceWith(path, ObjectExpression([]));
104
112
  }
105
-
@@ -2,11 +2,8 @@
2
2
 
3
3
  const putout = require('putout');
4
4
  const tryCatch = require('try-catch');
5
-
6
5
  const generateCode = require('./generate-code');
7
-
8
6
  const noop = () => {};
9
-
10
7
  const {operator} = putout;
11
8
  const {
12
9
  compare,
@@ -15,7 +12,6 @@ const {
15
12
  } = operator;
16
13
 
17
14
  const name = '__putout_plugin_check_replace_code';
18
-
19
15
  const get = (path) => path[name];
20
16
  const set = (path) => path[name] = true;
21
17
 
@@ -61,6 +57,7 @@ module.exports.traverse = ({push}) => ({
61
57
  mainPath: path,
62
58
  path: propertyPath,
63
59
  });
60
+
64
61
  return;
65
62
  }
66
63
 
@@ -73,6 +70,7 @@ module.exports.traverse = ({push}) => ({
73
70
  mainPath: path,
74
71
  path: propertyPath,
75
72
  });
73
+
76
74
  return;
77
75
  }
78
76
 
@@ -95,6 +93,7 @@ module.exports.traverse = ({push}) => ({
95
93
  mainPath: path,
96
94
  path: propertyPath,
97
95
  });
96
+
98
97
  return;
99
98
  }
100
99
 
@@ -116,13 +115,19 @@ function parseKey(propertyPath) {
116
115
  const [isComputed, key] = compute(keyPath);
117
116
 
118
117
  if (!isComputed)
119
- return [Error(`Replace key cannot be computed: '${keyPath.toString()}'`)];
118
+ return [
119
+ Error(`Replace key cannot be computed: '${keyPath.toString()}'`),
120
+ ];
120
121
 
121
- return [null, key];
122
+ return [
123
+ null,
124
+ key,
125
+ ];
122
126
  }
123
127
 
124
128
  function hasMatch(path) {
125
- const {body} = path.scope.getProgramParent().path.node;
129
+ const {body} = path.scope
130
+ .getProgramParent().path.node;
126
131
 
127
132
  for (const current of body) {
128
133
  if (compare(current, 'module.exports.match = __a'))
@@ -131,4 +136,3 @@ function hasMatch(path) {
131
136
 
132
137
  return false;
133
138
  }
134
-
@@ -8,4 +8,3 @@ module.exports.replace = () => ({
8
8
  return path;
9
9
  },
10
10
  });
11
-
@@ -17,16 +17,17 @@ module.exports.report = () => {
17
17
 
18
18
  function isRequire(path) {
19
19
  return path
20
- .get('callee')
21
- .isIdentifier({name: 'require'});
20
+ .get('callee').isIdentifier({
21
+ name: 'require',
22
+ });
22
23
  }
23
24
 
24
25
  function isBabelTypes(path) {
25
26
  return path
26
- .get('arguments.0')
27
- .isStringLiteral({value: '@babel/types'});
27
+ .get('arguments.0').isStringLiteral({
28
+ value: '@babel/types',
29
+ });
28
30
  }
29
-
30
31
  module.exports.traverse = ({push}) => ({
31
32
  CallExpression(path) {
32
33
  if (!isRequire(path))
@@ -42,4 +43,3 @@ module.exports.traverse = ({push}) => ({
42
43
  module.exports.fix = (path) => {
43
44
  replaceWith(path, astRequire);
44
45
  };
45
-
@@ -12,4 +12,3 @@ module.exports.match = () => ({
12
12
  module.exports.replace = () => ({
13
13
  'createTest(__dirname, __a)': 'createTest(import.meta.url, __a)',
14
14
  });
15
-
@@ -1,6 +1,10 @@
1
1
  'use strict';
2
2
 
3
- const {types, operator} = require('putout');
3
+ const {
4
+ types,
5
+ operator,
6
+ } = require('putout');
7
+
4
8
  const {replaceWith} = operator;
5
9
 
6
10
  const {
@@ -24,11 +28,9 @@ module.exports.fix = fixType({
24
28
  isMemberExpression: (path) => {
25
29
  path.get('property').node.name = 'traverse';
26
30
  },
27
-
28
31
  isFunction: (path) => {
29
32
  path.node.params = [path.node.params[1]];
30
33
  },
31
-
32
34
  isCallExpression: (path) => {
33
35
  replaceWith(path, ReturnStatement(path.node.arguments[1]));
34
36
  },
@@ -46,7 +48,6 @@ module.exports.traverse = ({push}) => ({
46
48
  return;
47
49
 
48
50
  const traverseCallPath = getTraverseCall(rightPath);
49
-
50
51
  push(traverseCallPath);
51
52
  push(leftPath);
52
53
  push(rightPath);
@@ -72,14 +73,16 @@ function getTraverseCall(path) {
72
73
 
73
74
  path.traverse({
74
75
  CallExpression(path) {
75
- if (!path.get('callee').isIdentifier({name: 'traverse'}))
76
+ if (!path.get('callee').isIdentifier({
77
+ name: 'traverse',
78
+ }))
76
79
  return;
77
80
 
78
81
  result = path;
82
+
79
83
  path.stop();
80
84
  },
81
85
  });
82
86
 
83
87
  return result;
84
88
  }
85
-
@@ -5,4 +5,3 @@ module.exports.report = () => `'match' should be a function`;
5
5
  module.exports.replace = () => ({
6
6
  'module.exports.match= __object': 'module.exports.match = () => __object',
7
7
  });
8
-
@@ -10,7 +10,9 @@ const {ObjectProperty} = types;
10
10
 
11
11
  module.exports.report = () => 'Object Property should be used instead of Method';
12
12
 
13
- module.exports.include = () => ['ObjectMethod'];
13
+ module.exports.include = () => [
14
+ 'ObjectMethod',
15
+ ];
14
16
 
15
17
  module.exports.filter = (path) => {
16
18
  if (!path.node.params.length)
@@ -26,9 +28,9 @@ module.exports.filter = (path) => {
26
28
 
27
29
  module.exports.fix = (path) => {
28
30
  const keyPath = path.get('key');
31
+
29
32
  path.node.type = 'ArrowFunctionExpression';
30
33
  path.node.id = null;
31
34
 
32
35
  replaceWith(path, ObjectProperty(keyPath.node, path.node));
33
36
  };
34
-
@@ -35,7 +35,6 @@ module.exports.traverse = ({push}) => ({
35
35
  'getTemplateValues(__a, __b)': (path) => {
36
36
  const {scope} = path;
37
37
  const {bindings} = scope;
38
-
39
38
  const __aPath = path.get('arguments.0');
40
39
 
41
40
  if (__aPath.isMemberExpression()) {
@@ -70,4 +69,3 @@ module.exports.traverse = ({push}) => ({
70
69
  });
71
70
  },
72
71
  });
73
-
@@ -23,4 +23,3 @@ module.exports.traverse = ({push}) => ({
23
23
  push(path);
24
24
  },
25
25
  });
26
-
@@ -28,4 +28,3 @@ module.exports.replace = () => ({
28
28
  return 'module.exports.find = __a';
29
29
  },
30
30
  });
31
-
@@ -3,7 +3,6 @@
3
3
  const {assign} = Object;
4
4
 
5
5
  module.exports.report = () => `Use 'createTest' instead of 'putoutTest'`;
6
-
7
6
  module.exports.filter = ({scope}) => !scope.bindings.createTest;
8
7
 
9
8
  module.exports.include = () => [
@@ -21,4 +20,3 @@ module.exports.fix = (path) => {
21
20
 
22
21
  path.scope.rename('putoutTest', 'createTest');
23
22
  };
24
-
@@ -5,4 +5,3 @@ module.exports.report = () => `'replace' should be a function`;
5
5
  module.exports.replace = () => ({
6
6
  'module.exports.replace = __object': 'module.exports.replace = () => __object',
7
7
  });
8
-
@@ -50,8 +50,7 @@ module.exports.fix = ({path, calleePath, property, object, program, isInserted})
50
50
  const id = Identifier('replaceWith');
51
51
  const varPath = getVarPath(bindings);
52
52
 
53
- varPath.node.id.properties
54
- .unshift(ObjectProperty(id, id, false, true));
53
+ varPath.node.id.properties.unshift(ObjectProperty(id, id, false, true));
55
54
  };
56
55
 
57
56
  function getVarPath(bindings) {
@@ -65,7 +64,6 @@ function getVarPath(bindings) {
65
64
 
66
65
  return insertAfter.path;
67
66
  }
68
-
69
67
  module.exports.traverse = ({push}) => {
70
68
  const isInserted = fullstore();
71
69
 
@@ -76,7 +74,10 @@ module.exports.traverse = ({push}) => {
76
74
  if (!calleePath.isMemberExpression())
77
75
  return;
78
76
 
79
- const {object, property} = calleePath.node;
77
+ const {
78
+ object,
79
+ property,
80
+ } = calleePath.node;
80
81
 
81
82
  if (property.name !== 'replaceWith')
82
83
  return;
@@ -94,4 +95,3 @@ module.exports.traverse = ({push}) => {
94
95
  },
95
96
  };
96
97
  };
97
-
@@ -38,10 +38,9 @@ module.exports.fix = ({path, calleePath, property, object, program}) => {
38
38
  return insertAfter(strictModePath, replaceWithAST);
39
39
 
40
40
  const id = Identifier('replaceWithMultiple');
41
-
42
41
  const varPath = getVarPath(bindings);
43
- varPath.node.id.properties
44
- .push(ObjectProperty(id, id, false, true));
42
+
43
+ varPath.node.id.properties.push(ObjectProperty(id, id, false, true));
45
44
  };
46
45
 
47
46
  function getVarPath(bindings) {
@@ -55,7 +54,6 @@ function getVarPath(bindings) {
55
54
 
56
55
  return insertAfter.path;
57
56
  }
58
-
59
57
  module.exports.traverse = ({push}) => ({
60
58
  CallExpression(path) {
61
59
  const calleePath = path.get('callee');
@@ -63,7 +61,10 @@ module.exports.traverse = ({push}) => ({
63
61
  if (!calleePath.isMemberExpression())
64
62
  return;
65
63
 
66
- const {object, property} = calleePath.node;
64
+ const {
65
+ object,
66
+ property,
67
+ } = calleePath.node;
67
68
 
68
69
  if (property.name !== 'replaceWithMultiple')
69
70
  return;
@@ -79,4 +80,3 @@ module.exports.traverse = ({push}) => ({
79
80
  });
80
81
  },
81
82
  });
82
-
@@ -16,7 +16,10 @@ module.exports.traverse = ({push}) => ({
16
16
  if (!calleePath.isMemberExpression())
17
17
  return;
18
18
 
19
- const {object, property} = calleePath.node;
19
+ const {
20
+ object,
21
+ property,
22
+ } = calleePath.node;
20
23
 
21
24
  if (object.name !== 't' || property.name !== 'transformCode')
22
25
  return;
@@ -40,4 +43,3 @@ module.exports.fix = ({path, calleePath}) => {
40
43
  calleePath.node.property = Identifier('noTransformCode');
41
44
  path.node.arguments.pop();
42
45
  };
43
-
@@ -5,12 +5,14 @@ const {
5
5
  template,
6
6
  operator,
7
7
  } = require('putout');
8
+
8
9
  const {StringLiteral} = types;
9
10
  const {compare} = operator;
10
11
 
11
- const isPush = (path) => path.get('value').isIdentifier({
12
- name: 'push',
13
- });
12
+ const isPush = (path) => path
13
+ .get('value').isIdentifier({
14
+ name: 'push',
15
+ });
14
16
 
15
17
  module.exports.report = () => 'Includer should be used instead of Traverser';
16
18
 
@@ -69,4 +71,3 @@ function isBlock(path) {
69
71
 
70
72
  return compare(node, 'push(path)');
71
73
  }
72
-
@@ -11,6 +11,7 @@ module.exports.report = () => 'Replacer should be used instead of Traverser (htt
11
11
  module.exports.match = () => ({
12
12
  'module.exports.traverse = (__args) => __a': ({__args}, path) => {
13
13
  const program = path.scope.getProgramParent().path;
14
+
14
15
  const withFix = contains(program, [
15
16
  'module.exports.fix = __a',
16
17
  ]);
@@ -54,6 +55,7 @@ function check(path) {
54
55
  return;
55
56
 
56
57
  hasTraverseMethod = true;
58
+
57
59
  path.stop();
58
60
  },
59
61
  'push(__a)': (path) => {
@@ -64,4 +66,3 @@ function check(path) {
64
66
 
65
67
  return hasPushCall || hasTraverseMethod;
66
68
  }
67
-
@@ -12,4 +12,3 @@ module.exports.match = () => ({
12
12
  module.exports.replace = () => ({
13
13
  'createTest(import.meta.url, __a)': 'createTest(__dirname, __a)',
14
14
  });
15
-
@@ -11,6 +11,7 @@ const {
11
11
  Identifier,
12
12
  ObjectProperty,
13
13
  ObjectExpression,
14
+ isIdentifier,
14
15
  } = types;
15
16
 
16
17
  const {
@@ -27,36 +28,53 @@ module.exports.include = () => [
27
28
  ];
28
29
 
29
30
  module.exports.fix = (path, {options}) => {
30
- const [name, value] = options.add;
31
31
  const objectPath = path.get('arguments.1');
32
32
 
33
33
  if (!getProperty(objectPath, 'plugins'))
34
34
  convert(objectPath);
35
35
 
36
- const property = ObjectProperty(Identifier(name), StringLiteral(value));
37
- objectPath.node.properties.unshift(property);
36
+ for (const [name, value] of options.add) {
37
+ if (getProperty(objectPath, name))
38
+ continue;
39
+
40
+ const property = ObjectProperty(Identifier(name), StringLiteral(value));
41
+ objectPath.node.properties.unshift(property);
42
+ }
38
43
  };
39
44
 
40
45
  module.exports.filter = (path, {options}) => {
41
46
  if (!options.add)
42
47
  return false;
43
48
 
44
- const [name] = options.add;
45
49
  const objectPath = path.get('arguments.1');
46
50
 
47
- return !getProperty(objectPath, name);
51
+ for (const [name] of options.add) {
52
+ if (!getProperty(objectPath, name))
53
+ return true;
54
+ }
55
+
56
+ return false;
57
+ };
58
+
59
+ const maybeLiteral = (a) => {
60
+ if (isIdentifier(a))
61
+ return StringLiteral(a.name);
62
+
63
+ return a;
48
64
  };
49
65
 
50
66
  function convert(objectPath) {
51
- const {key, value} = objectPath.node.properties[0];
67
+ const {
68
+ key,
69
+ value,
70
+ } = objectPath.node.properties[0];
52
71
 
53
72
  replaceWith(objectPath, ObjectExpression([
54
73
  ObjectProperty(Identifier('plugins'), ArrayExpression([
55
74
  ArrayExpression([
56
- key,
75
+ maybeLiteral(key),
57
76
  value,
58
77
  ]),
59
78
  ])),
60
79
  ]));
61
80
  }
62
-
@@ -9,4 +9,3 @@ module.exports.declare = () => ({
9
9
  ...operator,
10
10
  ...types,
11
11
  });
12
-
@@ -21,4 +21,3 @@ module.exports = {
21
21
  getProperty: `const {getProperty} = operator`,
22
22
  getProperties: `const {getProperties} = operator`,
23
23
  };
24
-
@@ -635,4 +635,4 @@
635
635
  "isRegexLiteral": "const {isRegexLiteral} = types",
636
636
  "isRestProperty": "const {isRestProperty} = types",
637
637
  "isSpreadProperty": "const {isSpreadProperty} = types"
638
- }
638
+ }
@@ -5,10 +5,8 @@ module.exports.report = () => 'Includer functions should return array (https://g
5
5
  module.exports.replace = () => ({
6
6
  'module.exports.include = () => "__a"': 'module.exports.include = ["__a"]',
7
7
  'module.exports.exclude = () => "__a"': 'module.exports.exclude = ["__a"]',
8
-
9
8
  'module.exports.include = ["__a"]': 'module.exports.include = () => ["__a"]',
10
9
  'module.exports.exclude = ["__a"]': 'module.exports.exclude = () => ["__a"]',
11
-
12
10
  'module.exports.include = "__a"': 'module.exports.include = ["__a"]',
13
11
  'module.exports.exclude = "__a"': 'module.exports.exclude= ["__a"]',
14
12
  });
package/lib/index.js CHANGED
@@ -41,4 +41,3 @@ module.exports.rules = {
41
41
  ...getRule('includer'),
42
42
  ...getRule('create-test'),
43
43
  };
44
-
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const justCamelCase = require('just-camel-case');
4
+
4
5
  const {
5
6
  types,
6
7
  template,
@@ -60,8 +61,11 @@ module.exports.replace = () => ({
60
61
  const buildRequire = template(`const NAME = REQUIRE`);
61
62
 
62
63
  function declareRequire({__a, __b}, path) {
63
- const shortName = (__a.value || __a.name).split('/').pop();
64
+ const shortName = __a.value || __a.name
65
+ .split('/').pop();
66
+
64
67
  const name = justCamelCase(shortName);
68
+
65
69
  const requireNode = buildRequire({
66
70
  NAME: Identifier(name),
67
71
  REQUIRE: __b,
@@ -70,9 +74,10 @@ function declareRequire({__a, __b}, path) {
70
74
  if (path.scope.hasBinding(name))
71
75
  return name;
72
76
 
73
- const programPath = path.scope.getProgramParent().path;
77
+ const programPath = path.scope
78
+ .getProgramParent().path;
79
+
74
80
  programPath.node.body.unshift(requireNode);
75
81
 
76
82
  return name;
77
83
  }
78
-
@@ -5,4 +5,3 @@ module.exports.report = () => '"operator" should be used instead of "operate"';
5
5
  module.exports.replace = () => ({
6
6
  'const __object = require("putout").operate': 'const __object = require("putout").operator',
7
7
  });
8
-
@@ -58,16 +58,22 @@ function isCorrect({path, incorrect}) {
58
58
  const calleePath = path.findParent(isCallExpression);
59
59
 
60
60
  if (!calleePath)
61
- return [CORRECT];
61
+ return [
62
+ CORRECT,
63
+ ];
62
64
 
63
65
  const messagePath = calleePath.get('arguments.0');
64
66
 
65
67
  if (!messagePath.isStringLiteral())
66
- return [CORRECT];
68
+ return [
69
+ CORRECT,
70
+ ];
67
71
 
68
72
  const {value} = messagePath.node;
69
73
  const is = !incorrect.test(value);
70
74
 
71
- return [is, messagePath];
75
+ return [
76
+ is,
77
+ messagePath,
78
+ ];
72
79
  }
73
-
@@ -6,4 +6,3 @@ module.exports.replace = () => ({
6
6
  'require("putout/lib/cli/process-file")': 'require("putout/process-file")',
7
7
  'require("putout/lib/parse-options")': 'require("putout/parse-options")',
8
8
  });
9
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "12.1.0",
3
+ "version": "12.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",