@putout/plugin-putout 10.1.0 → 11.0.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
@@ -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
 
@@ -24,6 +24,8 @@ npm i @putout/plugin-putout -D
24
24
  "putout/convert-to-no-transform-code": "on",
25
25
  "putout/convert-replace-with": "on",
26
26
  "putout/convert-replace-with-multiple": "on",
27
+ "putout/convert-replace-to-function": "on",
28
+ "putout/convert-match-to-function": "on",
27
29
  "putout/convert-babel-types": "on",
28
30
  "putout/convert-destructuring-to-identifier": "on",
29
31
  "putout/convert-node-to-path-in-get-template-values": "on",
@@ -45,7 +47,7 @@ npm i @putout/plugin-putout -D
45
47
 
46
48
  ## apply-processors-destructuring
47
49
 
48
- ### ❌ Incorrect code example
50
+ ### ❌ Example of incorrect code
49
51
 
50
52
  ```js
51
53
  test('', async (t) => {
@@ -54,7 +56,7 @@ test('', async (t) => {
54
56
 
55
57
  ```
56
58
 
57
- ### ✅ Correct code Example
59
+ ### ✅ Example of correct code
58
60
 
59
61
  ```js
60
62
  test('', async ({process}) => {
@@ -64,7 +66,7 @@ test('', async ({process}) => {
64
66
 
65
67
  ## apply-async-formatter
66
68
 
67
- ### ❌ Incorrect code example
69
+ ### ❌ Example of incorrect code
68
70
 
69
71
  ```js
70
72
  test('formatter: codeframea', (t) => {
@@ -73,7 +75,7 @@ test('formatter: codeframea', (t) => {
73
75
  });
74
76
  ```
75
77
 
76
- ### ✅ Correct code example
78
+ ### ✅ Example of correct code
77
79
 
78
80
  ```js
79
81
  test('formatter: codeframea', async ({format}) => {
@@ -83,7 +85,7 @@ test('formatter: codeframea', async ({format}) => {
83
85
 
84
86
  ## apply-create-test
85
87
 
86
- ### ❌ Incorrect code example
88
+ ### ❌ Example of incorrect code
87
89
 
88
90
  ```js
89
91
  const test = require('@putout/test')({
@@ -91,7 +93,7 @@ const test = require('@putout/test')({
91
93
  });
92
94
  ```
93
95
 
94
- ### ✅ Correct code example
96
+ ### ✅ Example of correct code
95
97
 
96
98
  ```js
97
99
  const {createTest} = require('@putout/test');
@@ -100,11 +102,11 @@ const test = createTest({
100
102
  });
101
103
  ```
102
104
 
103
- ## convert-putout-test-to-create-test"
105
+ ## convert-putout-test-to-create-test
104
106
 
105
107
  Fixes results of [@putout/convert-commonjs-to-esm](https://github.com/coderaiser/putout/tree/master/packages/plugin-convert-commonjs-to-esm) work.
106
108
 
107
- ### ❌ Incorrect code example
109
+ ### ❌ Example of incorrect code
108
110
 
109
111
  ```js
110
112
  import putoutTest from '@putout/test';
@@ -114,7 +116,7 @@ const test = putoutTest(__dirname, {
114
116
  });
115
117
  ```
116
118
 
117
- ### ✅ Correct code Example
119
+ ### ✅ Example of correct code
118
120
 
119
121
  ```js
120
122
  import createTest from '@putout/test';
@@ -126,7 +128,7 @@ const test = createTest(__dirname, {
126
128
 
127
129
  ## convert-to-no-transform-code
128
130
 
129
- ### ❌ Incorrect code example
131
+ ### ❌ Example of incorrect code
130
132
 
131
133
  ```js
132
134
  test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
@@ -137,7 +139,7 @@ test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
137
139
  });
138
140
  ```
139
141
 
140
- ### ✅ Correct code Example
142
+ ### ✅ Example of correct code
141
143
 
142
144
  ```js
143
145
  test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
@@ -150,7 +152,7 @@ test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
150
152
 
151
153
  ## convert-replace-with
152
154
 
153
- ### ❌ Incorrect code example
155
+ ### ❌ Example of incorrect code
154
156
 
155
157
  ```js
156
158
  module.exports.fix = (path) => {
@@ -158,7 +160,7 @@ module.exports.fix = (path) => {
158
160
  };
159
161
  ```
160
162
 
161
- ### ✅ Correct code Example
163
+ ### ✅ Example of correct code
162
164
 
163
165
  ```js
164
166
  const {replaceWith} = require('putout').operator;
@@ -170,7 +172,7 @@ module.exports.fix = (path) => {
170
172
 
171
173
  ## convert-replace-with-multiple
172
174
 
173
- ### ❌ Incorrect code example
175
+ ### ❌ Example of incorrect code
174
176
 
175
177
  ```js
176
178
  module.exports.fix = (path) => {
@@ -178,7 +180,7 @@ module.exports.fix = (path) => {
178
180
  };
179
181
  ```
180
182
 
181
- ### ✅ Correct code Example
183
+ ### ✅ Example of correct code
182
184
 
183
185
  ```js
184
186
  const {replaceWithMultiple} = require('putout').operator;
@@ -188,9 +190,45 @@ module.exports.fix = (path) => {
188
190
  };
189
191
  ```
190
192
 
193
+ ## convert-replace-to-function
194
+
195
+ ### ❌ Example of incorrect code
196
+
197
+ ```js
198
+ module.exports.replace = {
199
+ 'let __a = __b': 'const __b = __a',
200
+ };
201
+ ```
202
+
203
+ ### ✅ Example of correct code
204
+
205
+ ```js
206
+ module.exports.replace = () => ({
207
+ 'let __a = __b': 'const __b = __a',
208
+ });
209
+ ```
210
+
211
+ ## convert-match-to-function
212
+
213
+ ### ❌ Example of incorrect code
214
+
215
+ ```js
216
+ module.exports.match = {
217
+ 'let __a = __b': () => false,
218
+ };
219
+ ```
220
+
221
+ ### ✅ Example of correct code
222
+
223
+ ```js
224
+ module.exports.match = () => ({
225
+ 'let __a = __b': () => false,
226
+ });
227
+ ```
228
+
191
229
  ## convert-babel-types
192
230
 
193
- ### ❌ Incorrect code example
231
+ ### ❌ Example of incorrect code
194
232
 
195
233
  ```js
196
234
  const {
@@ -201,7 +239,7 @@ const {
201
239
  } = require('@babel/types');
202
240
  ```
203
241
 
204
- ### ✅ Correct code Example
242
+ ### ✅ Example of correct code
205
243
 
206
244
  ```js
207
245
  const {
@@ -214,7 +252,7 @@ const {
214
252
 
215
253
  ## convert-to-no-transform-code
216
254
 
217
- ### ❌ Incorrect code example
255
+ ### ❌ Example of incorrect code
218
256
 
219
257
  ```js
220
258
  module.exports.replace = () => ({
@@ -225,7 +263,7 @@ module.exports.replace = () => ({
225
263
  });
226
264
  ```
227
265
 
228
- ### ✅ Correct code Example
266
+ ### ✅ Example of correct code
229
267
 
230
268
  ```js
231
269
  module.exports.replace = () => ({
@@ -238,13 +276,13 @@ module.exports.replace = () => ({
238
276
 
239
277
  ## convert-node-to-path-in-get-template-values
240
278
 
241
- ### ❌ Incorrect code example
279
+ ### ❌ Example of incorrect code
242
280
 
243
281
  ```js
244
282
  const {__a, __b} = getTemplateValues(path.node, 'const __a = __b');
245
283
  ```
246
284
 
247
- ### ✅ Correct code Example
285
+ ### ✅ Example of correct code
248
286
 
249
287
  ```js
250
288
  const {__a, __b} = getTemplateValues(path, 'const __a = __b');
@@ -252,13 +290,13 @@ const {__a, __b} = getTemplateValues(path, 'const __a = __b');
252
290
 
253
291
  ## shorten-imports
254
292
 
255
- ### ❌ Incorrect code example
293
+ ### ❌ Example of incorrect code
256
294
 
257
295
  ```js
258
296
  const parseOptions = require('putout/lib/parse-options');
259
297
  ```
260
298
 
261
- ### ✅ Correct code Example
299
+ ### ✅ Example of correct code
262
300
 
263
301
  ```js
264
302
  const parseOptions = require('putout/parse-options');
@@ -266,7 +304,7 @@ const parseOptions = require('putout/parse-options');
266
304
 
267
305
  ## convert-traverse-to-include
268
306
 
269
- ### ❌ Incorrect code example
307
+ ### ❌ Example of incorrect code
270
308
 
271
309
  ```js
272
310
  module.exports.traverse = ({push}) => ({
@@ -276,7 +314,7 @@ module.exports.traverse = ({push}) => ({
276
314
  });
277
315
  ```
278
316
 
279
- ### ✅ Correct code Example
317
+ ### ✅ Example of correct code
280
318
 
281
319
  ```js
282
320
  module.exports.include = () => [
@@ -286,7 +324,7 @@ module.exports.include = () => [
286
324
 
287
325
  ## convert-traverse-to-replace
288
326
 
289
- ### ❌ Incorrect code example
327
+ ### ❌ Example of incorrect code
290
328
 
291
329
  ```js
292
330
  module.exports.traverse = () => ({
@@ -294,7 +332,7 @@ module.exports.traverse = () => ({
294
332
  });
295
333
  ```
296
334
 
297
- ### ✅ Correct code Example
335
+ ### ✅ Example of correct code
298
336
 
299
337
  ```js
300
338
  module.exports.replace = () => ({
@@ -304,14 +342,14 @@ module.exports.replace = () => ({
304
342
 
305
343
  ## convert-process-to-find
306
344
 
307
- ### ❌ Incorrect code example
345
+ ### ❌ Example of incorrect code
308
346
 
309
347
  ```js
310
348
  module.exports.preProcess = () => {};
311
349
  module.exports.postProcess = () => {};
312
350
  ```
313
351
 
314
- ### ✅ Correct code Example
352
+ ### ✅ Example of correct code
315
353
 
316
354
  ```js
317
355
  module.exports.branch = (rawSource) => [];
@@ -323,7 +361,7 @@ module.exports.merge = (processedSource, list) => '';
323
361
  - property simpler to work with;
324
362
  - support of `convert-destructuring-to-identifier` which is `Replacer`, while `convert-method-to-property` is `Includer` (searches for `ObjectMethod` node);
325
363
 
326
- ### ❌ Incorrect code example
364
+ ### ❌ Example of incorrect code
327
365
 
328
366
  ```js
329
367
  module.exports.match = () => ({
@@ -332,7 +370,7 @@ module.exports.match = () => ({
332
370
  });
333
371
  ```
334
372
 
335
- ### ✅ Correct code Example
373
+ ### ✅ Example of correct code
336
374
 
337
375
  ```js
338
376
  module.exports.match = () => ({
@@ -345,7 +383,7 @@ module.exports.match = () => ({
345
383
 
346
384
  Checks that [Replacer](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#replacer) transform is possible.
347
385
 
348
- ### ❌ Incorrect code example
386
+ ### ❌ Example of incorrect code
349
387
 
350
388
  ```js
351
389
  module.exports.replace = () => ({
@@ -361,14 +399,14 @@ This is additional tests, if you forget to test some case (from a big list of ru
361
399
  Depend on [@putout/convert-esm-to-commonjs](https://github.com/coderaiser/putout/tree/master/packages/plugin-convert-esm-to-commonjs) and
362
400
  [@putout/declare-undefined-variables](https://github.com/coderaiser/putout/tree/master/packages/plugin-declare-undefined-variables)
363
401
 
364
- ### ❌ Incorrect code example
402
+ ### ❌ Example of incorrect code
365
403
 
366
404
  ```js
367
405
  compare(a, 'const __a = __b');
368
406
  isIdentifier(a);
369
407
  ```
370
408
 
371
- ### ✅ Correct code Example
409
+ ### ✅ Example of correct code
372
410
 
373
411
  ```js
374
412
  const {operator, types} = require('putout');
@@ -381,7 +419,7 @@ isIdentifier(a);
381
419
 
382
420
  ## add-args
383
421
 
384
- ### ❌ Incorrect code example
422
+ ### ❌ Example of incorrect code
385
423
 
386
424
  ```js
387
425
  test('', () => {
@@ -389,7 +427,7 @@ test('', () => {
389
427
  });
390
428
  ```
391
429
 
392
- ### ✅ Correct code Example
430
+ ### ✅ Example of correct code
393
431
 
394
432
  ```js
395
433
  test('', ({comparePlaces}) => {
@@ -408,7 +446,7 @@ module.exports = addArgument({
408
446
  });
409
447
  ```
410
448
 
411
- ### ✅ Correct code Example
449
+ ### ✅ Example of correct code
412
450
 
413
451
  ```js
414
452
  const {operator} = require('putout');
@@ -432,7 +470,7 @@ const test = createTest(__dirname, {
432
470
  });
433
471
  ```
434
472
 
435
- ### ✅ Correct code Example
473
+ ### ✅ Example of correct code
436
474
 
437
475
  ```js
438
476
  import {createTest} from '@putout/test';
@@ -454,7 +492,7 @@ const test = createTest(import.meta.url, {
454
492
  });
455
493
  ```
456
494
 
457
- ### ✅ Correct code Example
495
+ ### ✅ Example of correct code
458
496
 
459
497
  ```js
460
498
  const {createTest} = require('@putout/test');
@@ -467,7 +505,7 @@ const test = createTest(import.meta.url, {
467
505
 
468
506
  ## move-require-on-top-level
469
507
 
470
- ### ❌ Incorrect code example
508
+ ### ❌ Example of incorrect code
471
509
 
472
510
  ```js
473
511
  const test = require('@putout/test')(__dirname, {
@@ -482,7 +520,7 @@ test('remove debugger: report', (t) => {
482
520
  });
483
521
  ```
484
522
 
485
- ### ✅ Correct code Example
523
+ ### ✅ Example of correct code
486
524
 
487
525
  ```js
488
526
  const removeDebugger = require('..');
@@ -500,7 +538,7 @@ test('remove debugger: report', (t) => {
500
538
 
501
539
  ## includer
502
540
 
503
- ### ❌ Incorrect code example
541
+ ### ❌ Example of incorrect code
504
542
 
505
543
  ```js
506
544
  module.exports.include = () => 'cons __a = __b';
@@ -513,7 +551,7 @@ module.exports.include = ['cons __a = __b'];
513
551
  module.exports.exclude = ['var __a = __b'];
514
552
  ```
515
553
 
516
- ### ✅ Correct code Example
554
+ ### ✅ Example of correct code
517
555
 
518
556
  ```js
519
557
  module.exports.include = () => ['cons __a = __b'];
@@ -9,6 +9,7 @@ const {
9
9
  ArrayPattern,
10
10
  ObjectPattern,
11
11
  BlockStatement,
12
+ ObjectExpression,
12
13
  } = types;
13
14
 
14
15
  module.exports = (rootPath, key) => {
@@ -56,10 +57,7 @@ module.exports = (rootPath, key) => {
56
57
  }
57
58
 
58
59
  if (name === '__object') {
59
- if (path.parentPath.isVariableDeclarator())
60
- replaceWith(path, ObjectPattern([]));
61
-
62
- return;
60
+ return objectify(path);
63
61
  }
64
62
 
65
63
  if (name === '__body') {
@@ -86,3 +84,15 @@ function createVarStore(path) {
86
84
  };
87
85
  }
88
86
 
87
+ function objectify(path) {
88
+ const {parentPath} = path;
89
+ const isVar = parentPath.isVariableDeclarator();
90
+ const isAssign = parentPath.isAssignmentExpression();
91
+
92
+ if (isVar && parentPath.get('id') === path)
93
+ return replaceWith(path, ObjectPattern([]));
94
+
95
+ if (isAssign && parentPath.get('right') === path)
96
+ return replaceWith(path, ObjectExpression([]));
97
+ }
98
+
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ module.exports.report = () => `'match' should be a function`;
4
+
5
+ module.exports.replace = () => ({
6
+ 'module.exports.match= __object': 'module.exports.match = () => __object',
7
+ });
8
+
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ module.exports.report = () => `'replace' should be a function`;
4
+
5
+ module.exports.replace = () => ({
6
+ 'module.exports.replace = __object': 'module.exports.replace = () => __object',
7
+ });
8
+
@@ -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
@@ -11,9 +11,11 @@ module.exports.rules = {
11
11
  ...getRule('convert-putout-test-to-create-test'),
12
12
  ...getRule('convert-to-no-transform-code'),
13
13
  ...getRule('convert-find-to-traverse'),
14
- ...getRule('convert-replace-with'),
15
14
  ...getRule('convert-destructuring-to-identifier'),
15
+ ...getRule('convert-replace-with'),
16
16
  ...getRule('convert-replace-with-multiple'),
17
+ ...getRule('convert-replace-to-function'),
18
+ ...getRule('convert-match-to-function'),
17
19
  ...getRule('convert-babel-types'),
18
20
  ...getRule('convert-node-to-path-in-get-template-values'),
19
21
  ...getRule('convert-traverse-to-include'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "10.1.0",
3
+ "version": "11.0.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",
@@ -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"