@putout/plugin-putout 10.2.0 → 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
@@ -3,7 +3,7 @@
3
3
  [NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-putout.svg?style=flat&longCache=true
4
4
  [NPMURL]: https://npmjs.org/package/@putout/plugin-putout"npm"
5
5
 
6
- 🐊[`Putout`](https://github.com/coderaiser/putout) plugin helps with plugins development.
6
+ 🐊[**Putout**](https://github.com/coderaiser/putout) plugin helps with plugins development.
7
7
 
8
8
  ## Install
9
9
 
@@ -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",
@@ -47,7 +48,7 @@ npm i @putout/plugin-putout -D
47
48
 
48
49
  ## apply-processors-destructuring
49
50
 
50
- ### ❌ Incorrect code example
51
+ ### ❌ Example of incorrect code
51
52
 
52
53
  ```js
53
54
  test('', async (t) => {
@@ -56,7 +57,7 @@ test('', async (t) => {
56
57
 
57
58
  ```
58
59
 
59
- ### ✅ Correct code Example
60
+ ### ✅ Example of correct code
60
61
 
61
62
  ```js
62
63
  test('', async ({process}) => {
@@ -66,7 +67,7 @@ test('', async ({process}) => {
66
67
 
67
68
  ## apply-async-formatter
68
69
 
69
- ### ❌ Incorrect code example
70
+ ### ❌ Example of incorrect code
70
71
 
71
72
  ```js
72
73
  test('formatter: codeframea', (t) => {
@@ -75,7 +76,7 @@ test('formatter: codeframea', (t) => {
75
76
  });
76
77
  ```
77
78
 
78
- ### ✅ Correct code example
79
+ ### ✅ Example of correct code
79
80
 
80
81
  ```js
81
82
  test('formatter: codeframea', async ({format}) => {
@@ -85,7 +86,7 @@ test('formatter: codeframea', async ({format}) => {
85
86
 
86
87
  ## apply-create-test
87
88
 
88
- ### ❌ Incorrect code example
89
+ ### ❌ Example of incorrect code
89
90
 
90
91
  ```js
91
92
  const test = require('@putout/test')({
@@ -93,7 +94,7 @@ const test = require('@putout/test')({
93
94
  });
94
95
  ```
95
96
 
96
- ### ✅ Correct code example
97
+ ### ✅ Example of correct code
97
98
 
98
99
  ```js
99
100
  const {createTest} = require('@putout/test');
@@ -102,11 +103,11 @@ const test = createTest({
102
103
  });
103
104
  ```
104
105
 
105
- ## convert-putout-test-to-create-test"
106
+ ## convert-putout-test-to-create-test
106
107
 
107
108
  Fixes results of [@putout/convert-commonjs-to-esm](https://github.com/coderaiser/putout/tree/master/packages/plugin-convert-commonjs-to-esm) work.
108
109
 
109
- ### ❌ Incorrect code example
110
+ ### ❌ Example of incorrect code
110
111
 
111
112
  ```js
112
113
  import putoutTest from '@putout/test';
@@ -116,7 +117,7 @@ const test = putoutTest(__dirname, {
116
117
  });
117
118
  ```
118
119
 
119
- ### ✅ Correct code Example
120
+ ### ✅ Example of correct code
120
121
 
121
122
  ```js
122
123
  import createTest from '@putout/test';
@@ -128,7 +129,7 @@ const test = createTest(__dirname, {
128
129
 
129
130
  ## convert-to-no-transform-code
130
131
 
131
- ### ❌ Incorrect code example
132
+ ### ❌ Example of incorrect code
132
133
 
133
134
  ```js
134
135
  test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
@@ -139,7 +140,7 @@ test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
139
140
  });
140
141
  ```
141
142
 
142
- ### ✅ Correct code Example
143
+ ### ✅ Example of correct code
143
144
 
144
145
  ```js
145
146
  test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
@@ -152,7 +153,7 @@ test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
152
153
 
153
154
  ## convert-replace-with
154
155
 
155
- ### ❌ Incorrect code example
156
+ ### ❌ Example of incorrect code
156
157
 
157
158
  ```js
158
159
  module.exports.fix = (path) => {
@@ -160,7 +161,7 @@ module.exports.fix = (path) => {
160
161
  };
161
162
  ```
162
163
 
163
- ### ✅ Correct code Example
164
+ ### ✅ Example of correct code
164
165
 
165
166
  ```js
166
167
  const {replaceWith} = require('putout').operator;
@@ -172,7 +173,7 @@ module.exports.fix = (path) => {
172
173
 
173
174
  ## convert-replace-with-multiple
174
175
 
175
- ### ❌ Incorrect code example
176
+ ### ❌ Example of incorrect code
176
177
 
177
178
  ```js
178
179
  module.exports.fix = (path) => {
@@ -180,7 +181,7 @@ module.exports.fix = (path) => {
180
181
  };
181
182
  ```
182
183
 
183
- ### ✅ Correct code Example
184
+ ### ✅ Example of correct code
184
185
 
185
186
  ```js
186
187
  const {replaceWithMultiple} = require('putout').operator;
@@ -192,7 +193,7 @@ module.exports.fix = (path) => {
192
193
 
193
194
  ## convert-replace-to-function
194
195
 
195
- ### ❌ Incorrect code example
196
+ ### ❌ Example of incorrect code
196
197
 
197
198
  ```js
198
199
  module.exports.replace = {
@@ -200,7 +201,7 @@ module.exports.replace = {
200
201
  };
201
202
  ```
202
203
 
203
- ### ✅ Correct code Example
204
+ ### ✅ Example of correct code
204
205
 
205
206
  ```js
206
207
  module.exports.replace = () => ({
@@ -210,7 +211,7 @@ module.exports.replace = () => ({
210
211
 
211
212
  ## convert-match-to-function
212
213
 
213
- ### ❌ Incorrect code example
214
+ ### ❌ Example of incorrect code
214
215
 
215
216
  ```js
216
217
  module.exports.match = {
@@ -218,7 +219,7 @@ module.exports.match = {
218
219
  };
219
220
  ```
220
221
 
221
- ### ✅ Correct code Example
222
+ ### ✅ Example of correct code
222
223
 
223
224
  ```js
224
225
  module.exports.match = () => ({
@@ -228,7 +229,7 @@ module.exports.match = () => ({
228
229
 
229
230
  ## convert-babel-types
230
231
 
231
- ### ❌ Incorrect code example
232
+ ### ❌ Example of incorrect code
232
233
 
233
234
  ```js
234
235
  const {
@@ -239,7 +240,7 @@ const {
239
240
  } = require('@babel/types');
240
241
  ```
241
242
 
242
- ### ✅ Correct code Example
243
+ ### ✅ Example of correct code
243
244
 
244
245
  ```js
245
246
  const {
@@ -252,7 +253,7 @@ const {
252
253
 
253
254
  ## convert-to-no-transform-code
254
255
 
255
- ### ❌ Incorrect code example
256
+ ### ❌ Example of incorrect code
256
257
 
257
258
  ```js
258
259
  module.exports.replace = () => ({
@@ -263,7 +264,7 @@ module.exports.replace = () => ({
263
264
  });
264
265
  ```
265
266
 
266
- ### ✅ Correct code Example
267
+ ### ✅ Example of correct code
267
268
 
268
269
  ```js
269
270
  module.exports.replace = () => ({
@@ -276,13 +277,13 @@ module.exports.replace = () => ({
276
277
 
277
278
  ## convert-node-to-path-in-get-template-values
278
279
 
279
- ### ❌ Incorrect code example
280
+ ### ❌ Example of incorrect code
280
281
 
281
282
  ```js
282
283
  const {__a, __b} = getTemplateValues(path.node, 'const __a = __b');
283
284
  ```
284
285
 
285
- ### ✅ Correct code Example
286
+ ### ✅ Example of correct code
286
287
 
287
288
  ```js
288
289
  const {__a, __b} = getTemplateValues(path, 'const __a = __b');
@@ -290,13 +291,13 @@ const {__a, __b} = getTemplateValues(path, 'const __a = __b');
290
291
 
291
292
  ## shorten-imports
292
293
 
293
- ### ❌ Incorrect code example
294
+ ### ❌ Example of incorrect code
294
295
 
295
296
  ```js
296
297
  const parseOptions = require('putout/lib/parse-options');
297
298
  ```
298
299
 
299
- ### ✅ Correct code Example
300
+ ### ✅ Example of correct code
300
301
 
301
302
  ```js
302
303
  const parseOptions = require('putout/parse-options');
@@ -304,7 +305,7 @@ const parseOptions = require('putout/parse-options');
304
305
 
305
306
  ## convert-traverse-to-include
306
307
 
307
- ### ❌ Incorrect code example
308
+ ### ❌ Example of incorrect code
308
309
 
309
310
  ```js
310
311
  module.exports.traverse = ({push}) => ({
@@ -314,7 +315,7 @@ module.exports.traverse = ({push}) => ({
314
315
  });
315
316
  ```
316
317
 
317
- ### ✅ Correct code Example
318
+ ### ✅ Example of correct code
318
319
 
319
320
  ```js
320
321
  module.exports.include = () => [
@@ -324,7 +325,7 @@ module.exports.include = () => [
324
325
 
325
326
  ## convert-traverse-to-replace
326
327
 
327
- ### ❌ Incorrect code example
328
+ ### ❌ Example of incorrect code
328
329
 
329
330
  ```js
330
331
  module.exports.traverse = () => ({
@@ -332,7 +333,7 @@ module.exports.traverse = () => ({
332
333
  });
333
334
  ```
334
335
 
335
- ### ✅ Correct code Example
336
+ ### ✅ Example of correct code
336
337
 
337
338
  ```js
338
339
  module.exports.replace = () => ({
@@ -342,14 +343,14 @@ module.exports.replace = () => ({
342
343
 
343
344
  ## convert-process-to-find
344
345
 
345
- ### ❌ Incorrect code example
346
+ ### ❌ Example of incorrect code
346
347
 
347
348
  ```js
348
349
  module.exports.preProcess = () => {};
349
350
  module.exports.postProcess = () => {};
350
351
  ```
351
352
 
352
- ### ✅ Correct code Example
353
+ ### ✅ Example of correct code
353
354
 
354
355
  ```js
355
356
  module.exports.branch = (rawSource) => [];
@@ -361,7 +362,7 @@ module.exports.merge = (processedSource, list) => '';
361
362
  - property simpler to work with;
362
363
  - support of `convert-destructuring-to-identifier` which is `Replacer`, while `convert-method-to-property` is `Includer` (searches for `ObjectMethod` node);
363
364
 
364
- ### ❌ Incorrect code example
365
+ ### ❌ Example of incorrect code
365
366
 
366
367
  ```js
367
368
  module.exports.match = () => ({
@@ -370,7 +371,7 @@ module.exports.match = () => ({
370
371
  });
371
372
  ```
372
373
 
373
- ### ✅ Correct code Example
374
+ ### ✅ Example of correct code
374
375
 
375
376
  ```js
376
377
  module.exports.match = () => ({
@@ -383,7 +384,7 @@ module.exports.match = () => ({
383
384
 
384
385
  Checks that [Replacer](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#replacer) transform is possible.
385
386
 
386
- ### ❌ Incorrect code example
387
+ ### ❌ Example of incorrect code
387
388
 
388
389
  ```js
389
390
  module.exports.replace = () => ({
@@ -399,14 +400,14 @@ This is additional tests, if you forget to test some case (from a big list of ru
399
400
  Depend on [@putout/convert-esm-to-commonjs](https://github.com/coderaiser/putout/tree/master/packages/plugin-convert-esm-to-commonjs) and
400
401
  [@putout/declare-undefined-variables](https://github.com/coderaiser/putout/tree/master/packages/plugin-declare-undefined-variables)
401
402
 
402
- ### ❌ Incorrect code example
403
+ ### ❌ Example of incorrect code
403
404
 
404
405
  ```js
405
406
  compare(a, 'const __a = __b');
406
407
  isIdentifier(a);
407
408
  ```
408
409
 
409
- ### ✅ Correct code Example
410
+ ### ✅ Example of correct code
410
411
 
411
412
  ```js
412
413
  const {operator, types} = require('putout');
@@ -419,7 +420,7 @@ isIdentifier(a);
419
420
 
420
421
  ## add-args
421
422
 
422
- ### ❌ Incorrect code example
423
+ ### ❌ Example of incorrect code
423
424
 
424
425
  ```js
425
426
  test('', () => {
@@ -427,7 +428,7 @@ test('', () => {
427
428
  });
428
429
  ```
429
430
 
430
- ### ✅ Correct code Example
431
+ ### ✅ Example of correct code
431
432
 
432
433
  ```js
433
434
  test('', ({comparePlaces}) => {
@@ -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
@@ -446,7 +469,7 @@ module.exports = addArgument({
446
469
  });
447
470
  ```
448
471
 
449
- ### ✅ Correct code Example
472
+ ### ✅ Example of correct code
450
473
 
451
474
  ```js
452
475
  const {operator} = require('putout');
@@ -470,7 +493,7 @@ const test = createTest(__dirname, {
470
493
  });
471
494
  ```
472
495
 
473
- ### ✅ Correct code Example
496
+ ### ✅ Example of correct code
474
497
 
475
498
  ```js
476
499
  import {createTest} from '@putout/test';
@@ -492,7 +515,7 @@ const test = createTest(import.meta.url, {
492
515
  });
493
516
  ```
494
517
 
495
- ### ✅ Correct code Example
518
+ ### ✅ Example of correct code
496
519
 
497
520
  ```js
498
521
  const {createTest} = require('@putout/test');
@@ -505,7 +528,7 @@ const test = createTest(import.meta.url, {
505
528
 
506
529
  ## move-require-on-top-level
507
530
 
508
- ### ❌ Incorrect code example
531
+ ### ❌ Example of incorrect code
509
532
 
510
533
  ```js
511
534
  const test = require('@putout/test')(__dirname, {
@@ -520,7 +543,7 @@ test('remove debugger: report', (t) => {
520
543
  });
521
544
  ```
522
545
 
523
- ### ✅ Correct code Example
546
+ ### ✅ Example of correct code
524
547
 
525
548
  ```js
526
549
  const removeDebugger = require('..');
@@ -538,7 +561,7 @@ test('remove debugger: report', (t) => {
538
561
 
539
562
  ## includer
540
563
 
541
- ### ❌ Incorrect code example
564
+ ### ❌ Example of incorrect code
542
565
 
543
566
  ```js
544
567
  module.exports.include = () => 'cons __a = __b';
@@ -551,7 +574,7 @@ module.exports.include = ['cons __a = __b'];
551
574
  module.exports.exclude = ['var __a = __b'];
552
575
  ```
553
576
 
554
- ### ✅ Correct code Example
577
+ ### ✅ Example of correct code
555
578
 
556
579
  ```js
557
580
  module.exports.include = () => ['cons __a = __b'];
@@ -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
+
@@ -10,7 +10,7 @@ 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
16
  isESM: `const {isESM} = operator`,
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": "10.2.0",
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",
@@ -36,22 +36,22 @@
36
36
  "putout"
37
37
  ],
38
38
  "devDependencies": {
39
- "@putout/test": "^4.0.0",
39
+ "@putout/test": "^5.0.0",
40
40
  "c8": "^7.5.0",
41
41
  "eslint": "^8.0.1",
42
42
  "eslint-plugin-node": "^11.0.0",
43
- "eslint-plugin-putout": "^13.0.0",
43
+ "eslint-plugin-putout": "^14.0.0",
44
44
  "lerna": "^4.0.0",
45
- "madrun": "^8.0.1",
45
+ "madrun": "^9.0.0",
46
46
  "montag": "^1.2.1",
47
47
  "nodemon": "^2.0.1"
48
48
  },
49
49
  "peerDependencies": {
50
- "putout": ">=24.2"
50
+ "putout": ">=25"
51
51
  },
52
52
  "license": "MIT",
53
53
  "engines": {
54
- "node": ">=14"
54
+ "node": ">=16"
55
55
  },
56
56
  "publishConfig": {
57
57
  "access": "public"