@putout/plugin-putout 12.1.0 → 12.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.
Files changed (37) hide show
  1. package/README.md +48 -28
  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 +17 -7
  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
@@ -87,6 +87,7 @@ export const fix = (path) => {
87
87
 
88
88
  ```js
89
89
  import {operator} from 'putout';
90
+
90
91
  const {remove} = operator;
91
92
 
92
93
  export const fix = (path) => {
@@ -153,6 +154,7 @@ const test = require('@putout/test')({
153
154
 
154
155
  ```js
155
156
  const {createTest} = require('@putout/test');
157
+
156
158
  const test = createTest({
157
159
  'remove-debugger': plugin,
158
160
  });
@@ -166,7 +168,9 @@ Add properties to `createTest` options, here is exmample of `.putout.json`:
166
168
  {
167
169
  "rules": {
168
170
  "putout/create-test": ["on", {
169
- "add": ["printer", "putout"]
171
+ "add": [
172
+ ["printer", "putout"]
173
+ ]
170
174
  }]
171
175
  }
172
176
  }
@@ -285,7 +289,9 @@ module.exports.fix = (path) => {
285
289
 
286
290
  ```js
287
291
  module.exports.fix = (path) => {
288
- path.replaceWithMultiple([Identifier('hello')]);
292
+ path.replaceWithMultiple([
293
+ Identifier('hello'),
294
+ ]);
289
295
  };
290
296
  ```
291
297
 
@@ -295,7 +301,9 @@ module.exports.fix = (path) => {
295
301
  const {replaceWithMultiple} = require('putout').operator;
296
302
 
297
303
  module.exports.fix = (path) => {
298
- replaceWithMultiple(path, [Identifier('hello')]);
304
+ replaceWithMultiple(path, [
305
+ Identifier('hello'),
306
+ ]);
299
307
  };
300
308
  ```
301
309
 
@@ -365,10 +373,8 @@ const {
365
373
 
366
374
  ```js
367
375
  module.exports.replace = () => ({
368
- 'const __a = __b': ({}) => {
369
- },
370
- 'const __c = __d': ({}, path) => {
371
- },
376
+ 'const __a = __b': ({}) => {},
377
+ 'const __c = __d': ({}, path) => {},
372
378
  });
373
379
  ```
374
380
 
@@ -376,10 +382,8 @@ module.exports.replace = () => ({
376
382
 
377
383
  ```js
378
384
  module.exports.replace = () => ({
379
- 'const __a = __b': (vars) => {
380
- },
381
- 'const __c = __d': (vars, path) => {
382
- },
385
+ 'const __a = __b': (vars) => {},
386
+ 'const __c = __d': (vars, path) => {},
383
387
  });
384
388
  ```
385
389
 
@@ -474,8 +478,7 @@ module.exports.merge = (processedSource, list) => '';
474
478
 
475
479
  ```js
476
480
  module.exports.match = () => ({
477
- 'module.exports.traverse = __a'({}, path) {
478
- },
481
+ 'module.exports.traverse = __a'({}, path) {},
479
482
  });
480
483
  ```
481
484
 
@@ -483,8 +486,7 @@ module.exports.match = () => ({
483
486
 
484
487
  ```js
485
488
  module.exports.match = () => ({
486
- 'module.exports.traverse = __a': ({}, path) => {
487
- },
489
+ 'module.exports.traverse = __a': ({}, path) => {},
488
490
  });
489
491
  ```
490
492
 
@@ -518,7 +520,10 @@ isIdentifier(a);
518
520
  ### ✅ Example of correct code
519
521
 
520
522
  ```js
521
- const {operator, types} = require('putout');
523
+ const {
524
+ operator,
525
+ types,
526
+ } = require('putout');
522
527
  const {compare} = operator;
523
528
  const {isIdentifier} = types;
524
529
 
@@ -598,6 +603,7 @@ module.exports = addArgs({
598
603
  import {createTest} from '@putout/test';
599
604
  import plugin from '@putout/plugin-debugger';
600
605
  import {createSimport} from 'simport';
606
+
601
607
  const {__dirname} = createSimport(import.meta.url);
602
608
 
603
609
  const test = createTest(__dirname, {
@@ -675,6 +681,7 @@ test('remove debugger: report', (t) => {
675
681
 
676
682
  ```js
677
683
  const removeDebugger = require('..');
684
+
678
685
  const test = require('@putout/test')(__dirname, {
679
686
  'remove-debugger': removeDebugger,
680
687
  });
@@ -683,6 +690,7 @@ test('remove debugger: report', (t) => {
683
690
  const test = require('@putout/test')(__dirname, {
684
691
  'remove-debugger': removeDebugger,
685
692
  });
693
+
686
694
  t.end();
687
695
  });
688
696
  ```
@@ -694,25 +702,37 @@ test('remove debugger: report', (t) => {
694
702
  ```js
695
703
  module.exports.include = () => 'cons __a = __b';
696
704
  module.exports.exclude = () => 'var __a = __b';
697
-
698
705
  module.exports.include = 'cons __a = __b';
699
706
  module.exports.exclude = 'var __a = __b';
700
-
701
- module.exports.include = ['cons __a = __b'];
702
- module.exports.exclude = ['var __a = __b'];
707
+ module.exports.include = [
708
+ 'cons __a = __b',
709
+ ];
710
+ module.exports.exclude = [
711
+ 'var __a = __b',
712
+ ];
703
713
  ```
704
714
 
705
715
  ### ✅ Example of correct code
706
716
 
707
717
  ```js
708
- module.exports.include = () => ['cons __a = __b'];
709
- module.exports.exclude = () => ['var __a = __b'];
710
-
711
- module.exports.include = () => ['cons __a = __b'];
712
- module.exports.exclude = () => ['var __a = __b'];
713
-
714
- module.exports.include = () => ['cons __a = __b'];
715
- module.exports.exclude = () => ['var __a = __b'];
718
+ module.exports.include = () => [
719
+ 'cons __a = __b',
720
+ ];
721
+ module.exports.exclude = () => [
722
+ 'var __a = __b',
723
+ ];
724
+ module.exports.include = () => [
725
+ 'cons __a = __b',
726
+ ];
727
+ module.exports.exclude = () => [
728
+ 'var __a = __b',
729
+ ];
730
+ module.exports.include = () => [
731
+ 'cons __a = __b',
732
+ ];
733
+ module.exports.exclude = () => [
734
+ 'var __a = __b',
735
+ ];
716
736
  ```
717
737
 
718
738
  ## 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
-
@@ -27,28 +27,39 @@ module.exports.include = () => [
27
27
  ];
28
28
 
29
29
  module.exports.fix = (path, {options}) => {
30
- const [name, value] = options.add;
31
30
  const objectPath = path.get('arguments.1');
32
31
 
33
32
  if (!getProperty(objectPath, 'plugins'))
34
33
  convert(objectPath);
35
34
 
36
- const property = ObjectProperty(Identifier(name), StringLiteral(value));
37
- objectPath.node.properties.unshift(property);
35
+ for (const [name, value] of options.add) {
36
+ if (getProperty(objectPath, name))
37
+ continue;
38
+
39
+ const property = ObjectProperty(Identifier(name), StringLiteral(value));
40
+ objectPath.node.properties.unshift(property);
41
+ }
38
42
  };
39
43
 
40
44
  module.exports.filter = (path, {options}) => {
41
45
  if (!options.add)
42
46
  return false;
43
47
 
44
- const [name] = options.add;
45
48
  const objectPath = path.get('arguments.1');
46
49
 
47
- return !getProperty(objectPath, name);
50
+ for (const [name] of options.add) {
51
+ if (!getProperty(objectPath, name))
52
+ return true;
53
+ }
54
+
55
+ return false;
48
56
  };
49
57
 
50
58
  function convert(objectPath) {
51
- const {key, value} = objectPath.node.properties[0];
59
+ const {
60
+ key,
61
+ value,
62
+ } = objectPath.node.properties[0];
52
63
 
53
64
  replaceWith(objectPath, ObjectExpression([
54
65
  ObjectProperty(Identifier('plugins'), ArrayExpression([
@@ -59,4 +70,3 @@ function convert(objectPath) {
59
70
  ])),
60
71
  ]));
61
72
  }
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.1.1",
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",