@putout/plugin-putout 29.26.0 → 29.27.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 +832 -862
- package/lib/declare/operator/index.js +1 -0
- package/lib/declare-template-variables/index.js +30 -3
- package/lib/sort-readme-file/index.js +2 -0
- package/lib/sort-readme-file/sort-contents/index.js +1 -1
- package/lib/sort-readme-file/sort-headings/index.js +166 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,21 +14,19 @@ npm i @putout/plugin-putout -D
|
|
|
14
14
|
## Rules
|
|
15
15
|
|
|
16
16
|
- ✅ [add-await-to-progress](#add-await-to-progress);
|
|
17
|
-
- ✅ [add-
|
|
18
|
-
- ✅ [add-path-arg-to-fix](#add-path-arg-to-fix);
|
|
17
|
+
- ✅ [add-crawl-file](#add-crawl-file);
|
|
19
18
|
- ✅ [add-path-arg-to-filter](#add-path-arg-to-filter);
|
|
20
|
-
- ✅ [add-path-arg-to-
|
|
19
|
+
- ✅ [add-path-arg-to-fix](#add-path-arg-to-fix);
|
|
21
20
|
- ✅ [add-path-arg-to-match](#add-path-arg-to-match);
|
|
21
|
+
- ✅ [add-path-arg-to-visitors](#add-path-arg-to-visitors);
|
|
22
|
+
- ✅ [add-places-to-compare-places](#add-places-to-compare-places);
|
|
22
23
|
- ✅ [add-push-arg](#add-push-arg);
|
|
23
24
|
- ✅ [add-test-args](#add-test-args);
|
|
24
|
-
- ✅ [add-traverse-args](#add-traverse-args);
|
|
25
|
-
- ✅ [add-crawl-file](#add-crawl-file);
|
|
26
25
|
- ✅ [add-track-file](#add-track-file);
|
|
26
|
+
- ✅ [add-traverse-args](#add-traverse-args);
|
|
27
27
|
- ✅ [apply-async-formatter](#apply-async-formatter);
|
|
28
|
-
- ✅ [apply-get-binding](#apply-get-binding);
|
|
29
|
-
- ✅ [apply-create-test](#apply-create-test);
|
|
30
|
-
- ✅ [apply-string-to-property-key](#apply-string-to-property-key);
|
|
31
28
|
- ✅ [apply-create-nested-directory](#apply-create-nested-directory);
|
|
29
|
+
- ✅ [apply-create-test](#apply-create-test);
|
|
32
30
|
- ✅ [apply-declare](#apply-declare);
|
|
33
31
|
- ✅ [apply-destructuring](#apply-destructuring);
|
|
34
32
|
- ✅ [apply-destructuring-to-options](#apply-destructuring);
|
|
@@ -37,65 +35,67 @@ npm i @putout/plugin-putout -D
|
|
|
37
35
|
- ✅ [apply-exports-to-add-args](#apply-exports-to-add-args);
|
|
38
36
|
- ✅ [apply-exports-to-match-files](#apply-exports-to-match-files);
|
|
39
37
|
- ✅ [apply-exports-to-rename-files](#apply-exports-to-rename-files);
|
|
40
|
-
- ✅ [apply-for-of-to-track-file](#apply-for-of-to-track-file);
|
|
41
38
|
- ✅ [apply-fixture-name-to-message](#apply-fixture-name-to-message);
|
|
39
|
+
- ✅ [apply-for-of-to-track-file](#apply-for-of-to-track-file);
|
|
40
|
+
- ✅ [apply-get-binding](#apply-get-binding);
|
|
42
41
|
- ✅ [apply-insert-after](#apply-insert-after);
|
|
43
42
|
- ✅ [apply-insert-before](#apply-insert-before);
|
|
44
|
-
- ✅ [apply-traverser-to-ignore](#apply-traverser-to-ignore);
|
|
45
|
-
- ✅ [apply-vars](#apply-vars);
|
|
46
|
-
- ✅ [apply-name-to-is-identifier](#apply-name-to-is-identifier);
|
|
47
43
|
- ✅ [apply-lowercase-to-node-builders](#apply-lowercase-to-node-builders);
|
|
44
|
+
- ✅ [apply-name-to-is-identifier](#apply-name-to-is-identifier);
|
|
48
45
|
- ✅ [apply-namespace-specifier](#apply-namespace-specifier);
|
|
49
|
-
- ✅ [apply-
|
|
46
|
+
- ✅ [apply-parens](#apply-parens);
|
|
50
47
|
- ✅ [apply-processors-destructuring](#apply-processors-destructuring);
|
|
51
48
|
- ✅ [apply-remove](#apply-remove);
|
|
52
49
|
- ✅ [apply-rename](#apply-rename);
|
|
53
|
-
- ✅ [apply-
|
|
50
|
+
- ✅ [apply-report](#apply-report);
|
|
54
51
|
- ✅ [apply-short-processors](#apply-short-processors);
|
|
52
|
+
- ✅ [apply-string-to-property-key](#apply-string-to-property-key);
|
|
55
53
|
- ✅ [apply-transform-with-options](#apply-transform-with-options);
|
|
56
|
-
- ✅ [
|
|
54
|
+
- ✅ [apply-traverser-to-ignore](#apply-traverser-to-ignore);
|
|
55
|
+
- ✅ [apply-vars](#apply-vars);
|
|
57
56
|
- ✅ [check-declare](#check-declare);
|
|
57
|
+
- ✅ [check-match](#check-match);
|
|
58
58
|
- ✅ [check-replace-code](#check-replace-code);
|
|
59
59
|
- ✅ [convert-add-argument-to-add-args](#convert-add-argument-to-add-test-args);
|
|
60
60
|
- ✅ [convert-babel-types](#convert-babel-types);
|
|
61
61
|
- ✅ [convert-destructuring-to-identifier](#convert-destructuring-to-identifier);
|
|
62
62
|
- ✅ [convert-dirname-to-url](#convert-dirname-to-url);
|
|
63
63
|
- ✅ [convert-find-to-traverse](#convert-find-to-traverse);
|
|
64
|
-
- ✅ [convert-get-rule-to-require](#convert-get-rule-to-require);
|
|
65
64
|
- ✅ [convert-get-file-content-to-read-file-content](#convert-get-file-content-to-read-file-content);
|
|
65
|
+
- ✅ [convert-get-rule-to-require](#convert-get-rule-to-require);
|
|
66
|
+
- ✅ [convert-include-to-traverse](#convert-include-to-traverse);
|
|
66
67
|
- ✅ [convert-match-to-function](#convert-match-to-function);
|
|
67
68
|
- ✅ [convert-method-to-property](#convert-method-to-property);
|
|
68
69
|
- ✅ [convert-node-to-path-in-get-template-values](#convert-node-to-path-in-get-template-values);
|
|
69
70
|
- ✅ [convert-number-to-numeric](#convert-number-to-numeric);
|
|
71
|
+
- ✅ [convert-plugins-element-to-tuple](#convert-plugins-element-to-tuple);
|
|
70
72
|
- ✅ [convert-process-to-find](#convert-process-to-find);
|
|
71
73
|
- ✅ [convert-progress-to-track-file](#convert-progress-to-track-file);
|
|
72
|
-
- ✅ [convert-putout-test-to-create-test](#convert-putout-test-to-create-test);
|
|
73
|
-
- ✅ [convert-plugins-element-to-tuple](#convert-plugins-element-to-tuple);
|
|
74
74
|
- ✅ [convert-push-object-to-push-path](#convert-push-object-to-push-path);
|
|
75
|
+
- ✅ [convert-putout-test-to-create-test](#convert-putout-test-to-create-test);
|
|
75
76
|
- ✅ [convert-replace-to-function](#convert-replace-to-function);
|
|
76
77
|
- ✅ [convert-replace-to-traverse](#convert-replace-to-traverse);
|
|
77
78
|
- ✅ [convert-replace-with](#convert-replace-with);
|
|
78
79
|
- ✅ [convert-replace-with-multiple](#convert-replace-with-multiple);
|
|
79
80
|
- ✅ [convert-report-to-function](#convert-report-to-function);
|
|
80
81
|
- ✅ [convert-to-no-transform-code](#convert-to-no-transform-code);
|
|
81
|
-
- ✅ [convert-include-to-traverse](#convert-include-to-traverse);
|
|
82
82
|
- ✅ [convert-traverse-to-include](#convert-traverse-to-include);
|
|
83
|
-
- ✅ [convert-traverse-to-super-traverse](#convert-traverse-to-super-traverse);
|
|
84
83
|
- ✅ [convert-traverse-to-replace](#convert-traverse-to-replace);
|
|
85
84
|
- ✅ [convert-traverse-to-scan](#convert-traverse-to-scan);
|
|
85
|
+
- ✅ [convert-traverse-to-super-traverse](#convert-traverse-to-super-traverse);
|
|
86
86
|
- ✅ [convert-url-to-dirname](#convert-url-to-dirname);
|
|
87
87
|
- ✅ [create-test](#create-test);
|
|
88
88
|
- ✅ [declare](#declare);
|
|
89
|
-
- ✅ [declare-template-variables](#declare-template-variables);
|
|
90
89
|
- ✅ [declare-path-variable](#declare-path-variable);
|
|
90
|
+
- ✅ [declare-template-variables](#declare-template-variables);
|
|
91
91
|
- ✅ [includer](#includer);
|
|
92
92
|
- ✅ [move-require-on-top-level](#move-require-on-top-level);
|
|
93
93
|
- ✅ [remove-empty-array-from-process](#remove-empty-array-from-process);
|
|
94
94
|
- ✅ [remove-empty-object-from-transform](#remove-empty-object-from-transform);
|
|
95
|
+
- ✅ [remove-message-from-no-report-after-transform](#remove-message-from-no-report-after-transform);
|
|
95
96
|
- ✅ [remove-unused-get-properties-argument](#remove-unused-get-properties-argument);
|
|
96
97
|
- ✅ [remove-useless-printer-option](#remove-useless-printer-option);
|
|
97
98
|
- ✅ [remove-useless-source-argument](#remove-useless-source-argument);
|
|
98
|
-
- ✅ [remove-message-from-no-report-after-transform](#remove-message-from-no-report-after-transform);
|
|
99
99
|
- ✅ [rename-operate-to-operator](#rename-operate-to-operator);
|
|
100
100
|
- ✅ [replace-operate-with-operator](#replace-operate-with-operator);
|
|
101
101
|
- ✅ [replace-test-message](#replace-test-message);
|
|
@@ -203,397 +203,295 @@ npm i @putout/plugin-putout -D
|
|
|
203
203
|
}
|
|
204
204
|
```
|
|
205
205
|
|
|
206
|
-
##
|
|
206
|
+
## add-await-to-progress
|
|
207
207
|
|
|
208
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/
|
|
208
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/978d70945edfa369390ea059654ff04d/89225c04039b9c0e9057aad34852c9428264f119).
|
|
209
209
|
|
|
210
210
|
### ❌ Example of incorrect code
|
|
211
211
|
|
|
212
212
|
```js
|
|
213
|
-
|
|
213
|
+
const {replaceWith} = require('putout').operator;
|
|
214
|
+
|
|
215
|
+
module.exports.fix = (path) => {
|
|
216
|
+
replaceWith(path, identifier('hello'));
|
|
217
|
+
};
|
|
214
218
|
```
|
|
215
219
|
|
|
216
220
|
### ✅ Example of correct code
|
|
217
221
|
|
|
218
222
|
```js
|
|
219
|
-
|
|
223
|
+
module.exports.fix = (path) => {
|
|
224
|
+
path.replaceWithMultiple([
|
|
225
|
+
identifier('hello'),
|
|
226
|
+
]);
|
|
227
|
+
};
|
|
220
228
|
```
|
|
221
229
|
|
|
222
|
-
##
|
|
230
|
+
## add-crawl-file
|
|
223
231
|
|
|
224
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/
|
|
232
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/4faf27234e9c5616444d0cabd79f00be/aac768e7150635d96cd71507e4a6eb43d0899814).
|
|
225
233
|
|
|
226
234
|
### ❌ Example of incorrect code
|
|
227
235
|
|
|
228
236
|
```js
|
|
229
|
-
|
|
237
|
+
const {replaceWithMultiple} = require('putout').operator;
|
|
238
|
+
|
|
239
|
+
module.exports.fix = (path) => {
|
|
240
|
+
replaceWithMultiple(path, [
|
|
241
|
+
identifier('hello'),
|
|
242
|
+
]);
|
|
243
|
+
};
|
|
230
244
|
```
|
|
231
245
|
|
|
232
246
|
### ✅ Example of correct code
|
|
233
247
|
|
|
234
248
|
```js
|
|
235
|
-
|
|
249
|
+
module.exports.replace = {
|
|
250
|
+
'let __a = __b': 'const __b = __a',
|
|
251
|
+
};
|
|
236
252
|
```
|
|
237
253
|
|
|
238
|
-
##
|
|
254
|
+
## add-path-arg-to-filter
|
|
239
255
|
|
|
240
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/
|
|
256
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/00a5e23e6a1a708937ef3fae2a792f86/c2fc350831f777bbb383fb65216b349edd4ec53d).
|
|
241
257
|
|
|
242
258
|
### ❌ Example of incorrect code
|
|
243
259
|
|
|
244
260
|
```js
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
261
|
+
createTest(__dirname, {
|
|
262
|
+
printer: 'putout',
|
|
263
|
+
plugins: [
|
|
264
|
+
['putout/create-test', plugin],
|
|
265
|
+
],
|
|
248
266
|
});
|
|
249
|
-
|
|
250
|
-
t.noReportWithOptions('rename-files-full');
|
|
251
|
-
|
|
252
|
-
t.noReport('a', 'Use b');
|
|
253
|
-
t.report('a');
|
|
254
267
|
```
|
|
255
268
|
|
|
256
269
|
### ✅ Example of correct code
|
|
257
270
|
|
|
258
271
|
```js
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
to: [],
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
t.noReport('rename-files-full');
|
|
265
|
-
|
|
266
|
-
t.report('a', 'Use b');
|
|
267
|
-
t.noReport('a');
|
|
272
|
+
const {isNumberLiteral} = types;
|
|
273
|
+
isNumberLiteral(node);
|
|
268
274
|
```
|
|
269
275
|
|
|
270
|
-
##
|
|
276
|
+
## add-path-arg-to-fix
|
|
271
277
|
|
|
272
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/
|
|
278
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/3d3fb6b8f5e5376cdd1674c9b19e0e27/4872f77e680a2fc443618f4bf5fae3ffab11046a).
|
|
273
279
|
|
|
274
280
|
### ❌ Example of incorrect code
|
|
275
281
|
|
|
276
282
|
```js
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
283
|
+
__putout_processor_json({
|
|
284
|
+
rules: {
|
|
285
|
+
'putout/create-test': ['on', {
|
|
286
|
+
add: [
|
|
287
|
+
['printer', 'putout'],
|
|
288
|
+
],
|
|
289
|
+
}],
|
|
281
290
|
},
|
|
282
|
-
};
|
|
291
|
+
});
|
|
283
292
|
```
|
|
284
293
|
|
|
285
294
|
### ✅ Example of correct code
|
|
286
295
|
|
|
287
296
|
```js
|
|
288
|
-
|
|
289
|
-
'
|
|
290
|
-
|
|
291
|
-
return path;
|
|
292
|
-
},
|
|
293
|
-
};
|
|
297
|
+
createTest(__dirname, {
|
|
298
|
+
'putout/create-test': plugin,
|
|
299
|
+
});
|
|
294
300
|
```
|
|
295
301
|
|
|
296
|
-
##
|
|
302
|
+
## add-path-arg-to-match
|
|
297
303
|
|
|
298
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/
|
|
304
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/35189d0e47c6ad1ca369e5a9287a34c1/d5fa7513a44fecc86beabd1faa8542bee7bc3e5e).
|
|
299
305
|
|
|
300
306
|
### ❌ Example of incorrect code
|
|
301
307
|
|
|
302
308
|
```js
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
insideSubmenu: true,
|
|
306
|
-
});
|
|
309
|
+
const {isNumericLiteral} = types;
|
|
310
|
+
isNumericLiteral(node);
|
|
307
311
|
```
|
|
308
312
|
|
|
309
313
|
### ✅ Example of correct code
|
|
310
314
|
|
|
311
315
|
```js
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
316
|
+
import putoutTest from '@putout/test';
|
|
317
|
+
|
|
318
|
+
const test = putoutTest(__dirname, {
|
|
319
|
+
'remove-unused-variables': rmVars,
|
|
315
320
|
});
|
|
316
321
|
```
|
|
317
322
|
|
|
318
|
-
##
|
|
323
|
+
## add-path-arg-to-visitors
|
|
324
|
+
|
|
325
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e20eb16668b2ebbceca1a03cde859e93/fee08d6dbb6aa4d835adacc8e9de4d994fd34848).
|
|
319
326
|
|
|
320
327
|
### ❌ Example of incorrect code
|
|
321
328
|
|
|
322
329
|
```js
|
|
323
|
-
|
|
324
|
-
|
|
330
|
+
import {createTest} from '@putout/test';
|
|
331
|
+
|
|
332
|
+
const test = createTest(__dirname, {
|
|
333
|
+
'remove-unused-variables': rmVars,
|
|
325
334
|
});
|
|
326
335
|
```
|
|
327
336
|
|
|
328
337
|
### ✅ Example of correct code
|
|
329
338
|
|
|
330
339
|
```js
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
340
|
+
t.transform('nested-not-block', [
|
|
341
|
+
['convert-if-to-jmp', convertIfToJmp],
|
|
342
|
+
convertDoWhileToJnz,
|
|
343
|
+
]);
|
|
334
344
|
```
|
|
335
345
|
|
|
336
|
-
##
|
|
346
|
+
## add-push-arg
|
|
347
|
+
|
|
348
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/cae7b14fa6be0fe50b134839bea1e544/37f9d161146dbe4f0497f852ba54161a759f7cbd).
|
|
337
349
|
|
|
338
350
|
### ❌ Example of incorrect code
|
|
339
351
|
|
|
340
352
|
```js
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
353
|
+
t.transform('nested-not-block', [
|
|
354
|
+
['convert-if-to-jmp', convertIfToJmp],
|
|
355
|
+
['convert-do-while-to-jnz', convertDoWhileToJnz],
|
|
356
|
+
]);
|
|
344
357
|
```
|
|
345
358
|
|
|
346
359
|
### ✅ Example of correct code
|
|
347
360
|
|
|
348
361
|
```js
|
|
349
|
-
|
|
350
|
-
|
|
362
|
+
export const fix = ({path}) => {
|
|
363
|
+
removeClassName(path, SELECTED);
|
|
364
|
+
};
|
|
365
|
+
push({
|
|
366
|
+
path: child,
|
|
351
367
|
});
|
|
352
368
|
```
|
|
353
369
|
|
|
354
|
-
##
|
|
355
|
-
|
|
356
|
-
Apply short names of processors, for example `__json` instead of `__putout_processor_json` . Checkout out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/908151edd3ee8d6a07d589df1e863883/1bd1eeadadea40915a2079f33a3845fa4fedda8e).
|
|
370
|
+
## add-test-args
|
|
357
371
|
|
|
358
372
|
### ❌ Example of incorrect code
|
|
359
373
|
|
|
360
374
|
```js
|
|
361
|
-
export const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
'__putout_processor_filesystem(__a)': ({__a}) => {
|
|
366
|
-
const list = __a.elements.map(getValue);
|
|
367
|
-
},
|
|
368
|
-
});
|
|
375
|
+
export const fix = (path) => {
|
|
376
|
+
removeClassName(path, SELECTED);
|
|
377
|
+
};
|
|
378
|
+
push(child);
|
|
369
379
|
```
|
|
370
380
|
|
|
371
381
|
### ✅ Example of correct code
|
|
372
382
|
|
|
373
383
|
```js
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
const list = __object.elements.map(getValue);
|
|
380
|
-
},
|
|
384
|
+
test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
|
|
385
|
+
const code = 'const {name} = array[0]';
|
|
386
|
+
|
|
387
|
+
t.transform(code, '');
|
|
388
|
+
t.end();
|
|
381
389
|
});
|
|
382
390
|
```
|
|
383
391
|
|
|
384
|
-
##
|
|
392
|
+
## add-track-file
|
|
385
393
|
|
|
386
|
-
|
|
387
|
-
Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/22716f61af86351331fc92260b7ed8e6/1435f31954764c119813e03654caa36e6a2a666b).
|
|
394
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/faaba1ce41e6fd274bc82a8875a52bfa/b34a22fdf9080e6b2f06703760f629d83d69ff3d).
|
|
388
395
|
|
|
389
396
|
### ❌ Example of incorrect code
|
|
390
397
|
|
|
391
398
|
```js
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
};
|
|
399
|
+
module.exports.replace = () => ({
|
|
400
|
+
'let __a = __b': 'const __b = __a',
|
|
401
|
+
});
|
|
395
402
|
```
|
|
396
403
|
|
|
397
404
|
### ✅ Example of correct code
|
|
398
405
|
|
|
399
406
|
```js
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
};
|
|
407
|
+
export const fix = () => {};
|
|
408
|
+
export const replace = () => ({
|
|
409
|
+
[__json]: (path) => {
|
|
410
|
+
const __aPath = path.get('arguments.0');
|
|
411
|
+
const {importsPath} = getProperties(__aPath, ['imports']);
|
|
412
|
+
},
|
|
413
|
+
});
|
|
407
414
|
```
|
|
408
415
|
|
|
409
|
-
##
|
|
410
|
-
|
|
411
|
-
Better use [`addParens(path)`](https://github.com/coderaiser/putout/tree/master/packages/operate#addparenspath-path) method of `operator` instead of using `path.node.extra` to have support of both printers:
|
|
416
|
+
## add-traverse-args
|
|
412
417
|
|
|
413
|
-
|
|
414
|
-
|
|
418
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/b453bd78b8e9380da8b2f33dfb38b4e2/53b14f89eb88aa10c8e00ba1f0251976592e14ee).
|
|
419
|
+
Supported args:
|
|
415
420
|
|
|
416
|
-
|
|
421
|
+
- `push`:
|
|
417
422
|
|
|
418
423
|
### ❌ Example of incorrect code
|
|
419
424
|
|
|
420
425
|
```js
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
+
test('plugin-apply-destructuring: transform: array: destructuring', (t) => {
|
|
427
|
+
const code = 'const {name} = array[0]';
|
|
428
|
+
|
|
429
|
+
t.noTransformCode(code);
|
|
430
|
+
t.end();
|
|
431
|
+
});
|
|
426
432
|
```
|
|
427
433
|
|
|
428
434
|
### ✅ Example of correct code
|
|
429
435
|
|
|
430
436
|
```js
|
|
431
|
-
|
|
432
|
-
|
|
437
|
+
module.exports.fix = (path) => {
|
|
438
|
+
path.replaceWith(identifier('hello'));
|
|
439
|
+
};
|
|
440
|
+
```
|
|
433
441
|
|
|
434
|
-
|
|
435
|
-
return;
|
|
436
|
-
```
|
|
437
|
-
|
|
438
|
-
## apply-remove
|
|
439
|
-
|
|
440
|
-
Better to use [`remove(path)`](https://github.com/coderaiser/putout/tree/master/packages/operate#removepath) method of `operator`.
|
|
441
|
-
It helps to preserve comments.
|
|
442
|
-
|
|
443
|
-
### ❌ Example of incorrect code
|
|
444
|
-
|
|
445
|
-
```js
|
|
446
|
-
export const fix = (path) => {
|
|
447
|
-
path.remove();
|
|
448
|
-
};
|
|
449
|
-
```
|
|
450
|
-
|
|
451
|
-
### ✅ Example of correct code
|
|
452
|
-
|
|
453
|
-
```js
|
|
454
|
-
import {operator} from 'putout';
|
|
455
|
-
|
|
456
|
-
const {remove} = operator;
|
|
457
|
-
|
|
458
|
-
export const fix = (path) => {
|
|
459
|
-
remove(path);
|
|
460
|
-
};
|
|
461
|
-
```
|
|
462
|
-
|
|
463
|
-
## apply-insert-before
|
|
464
|
-
|
|
465
|
-
Better to use [`insertBefore(a, b)`](https://github.com/coderaiser/putout/tree/master/packages/operate#insert-before) method of `operator`.
|
|
466
|
-
|
|
467
|
-
### ❌ Example of incorrect code
|
|
468
|
-
|
|
469
|
-
```js
|
|
470
|
-
export const fix = (path) => {
|
|
471
|
-
path.insertBefore(path.get('init'));
|
|
472
|
-
};
|
|
473
|
-
```
|
|
474
|
-
|
|
475
|
-
### ✅ Example of correct code
|
|
476
|
-
|
|
477
|
-
```js
|
|
478
|
-
import {operator} from 'putout';
|
|
479
|
-
|
|
480
|
-
const {insertBefore} = operator;
|
|
481
|
-
|
|
482
|
-
export const fix = (path) => {
|
|
483
|
-
insertBefore(path, path.get('init'));
|
|
484
|
-
};
|
|
485
|
-
```
|
|
486
|
-
|
|
487
|
-
## apply-insert-after
|
|
488
|
-
|
|
489
|
-
Better to use [`insertAfter(a, b)`](https://github.com/coderaiser/putout/tree/master/packages/operate#insert-after) method of `operator`.
|
|
490
|
-
It helps to avoid duplication of comments.
|
|
491
|
-
|
|
492
|
-
### ❌ Example of incorrect code
|
|
493
|
-
|
|
494
|
-
```js
|
|
495
|
-
export const fix = (path) => {
|
|
496
|
-
path.insertAfter(path.get('init'));
|
|
497
|
-
};
|
|
498
|
-
```
|
|
499
|
-
|
|
500
|
-
### ✅ Example of correct code
|
|
501
|
-
|
|
502
|
-
```js
|
|
503
|
-
import {operator} from 'putout';
|
|
504
|
-
|
|
505
|
-
const {insertAfter} = operator;
|
|
506
|
-
|
|
507
|
-
export const fix = (path) => {
|
|
508
|
-
insertAfter(path, path.get('init'));
|
|
509
|
-
};
|
|
510
|
-
```
|
|
511
|
-
|
|
512
|
-
## apply-traverser-to-ignore
|
|
513
|
-
|
|
514
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/ff74cf775696df17a5ba96c7ec309821/1cbdee25af883ccefd0a3614fe8424d8690fc58a).
|
|
442
|
+
## apply-async-formatter
|
|
515
443
|
|
|
516
444
|
### ❌ Example of incorrect code
|
|
517
445
|
|
|
518
446
|
```js
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
replace,
|
|
523
|
-
} = ignore({
|
|
524
|
-
type: __json,
|
|
525
|
-
name: '.nycrc.json',
|
|
526
|
-
field: 'exclude',
|
|
527
|
-
list: ['*.config.*'],
|
|
447
|
+
test('formatter: codeframea', (t) => {
|
|
448
|
+
t.format(codeframe, 1);
|
|
449
|
+
t.end();
|
|
528
450
|
});
|
|
529
451
|
```
|
|
530
452
|
|
|
531
453
|
### ✅ Example of correct code
|
|
532
454
|
|
|
533
455
|
```js
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
fix,
|
|
537
|
-
traverse,
|
|
538
|
-
} = ignore({
|
|
539
|
-
type: __json,
|
|
540
|
-
name: '.nycrc.json',
|
|
541
|
-
field: 'exclude',
|
|
542
|
-
list: ['*.config.*'],
|
|
456
|
+
test('formatter: codeframea', async ({format}) => {
|
|
457
|
+
await format(codeframe, 1);
|
|
543
458
|
});
|
|
544
459
|
```
|
|
545
460
|
|
|
546
|
-
## apply-
|
|
461
|
+
## apply-create-nested-directory
|
|
547
462
|
|
|
548
|
-
Checkout in
|
|
463
|
+
Checkout in [**Putout Editor**](https://putout.cloudcmd.io/#/gist/d97578b334963b2f573d1980a61034de/0b876a781268916344fa0ed4c19bdbc9fd7bbc3f).
|
|
549
464
|
|
|
550
465
|
### ❌ Example of incorrect code
|
|
551
466
|
|
|
552
467
|
```js
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
return true;
|
|
556
|
-
},
|
|
557
|
-
});
|
|
558
|
-
|
|
559
|
-
export const match = () => ({
|
|
560
|
-
'__a(__args': ({}, path) => {
|
|
561
|
-
return '';
|
|
562
|
-
},
|
|
563
|
-
});
|
|
468
|
+
const dirPath = createDirectory(path, '/hello/world');
|
|
469
|
+
const dirPath2 = createNestedDirectory(path, 'world');
|
|
564
470
|
```
|
|
565
471
|
|
|
566
472
|
### ✅ Example of correct code
|
|
567
473
|
|
|
568
474
|
```js
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
return true;
|
|
572
|
-
},
|
|
573
|
-
});
|
|
574
|
-
|
|
575
|
-
export const match = () => ({
|
|
576
|
-
'__a(__args': (vars, path) => {
|
|
577
|
-
return '';
|
|
578
|
-
},
|
|
579
|
-
});
|
|
475
|
+
const dirPath = createNestedDirectory(path, '/hello/world');
|
|
476
|
+
const dirPath2 = createDirectory(path, 'world');
|
|
580
477
|
```
|
|
581
478
|
|
|
582
|
-
## apply-
|
|
583
|
-
|
|
584
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/9d416e21377a53ef13066007f7037bdf/e179718fe1908851c26f10ba84fab1bf7ebca3ce).
|
|
479
|
+
## apply-create-test
|
|
585
480
|
|
|
586
481
|
### ❌ Example of incorrect code
|
|
587
482
|
|
|
588
483
|
```js
|
|
589
|
-
|
|
484
|
+
const test = require('@putout/test')({
|
|
485
|
+
'remove-debugger': plugin,
|
|
486
|
+
});
|
|
590
487
|
```
|
|
591
488
|
|
|
592
489
|
### ✅ Example of correct code
|
|
593
490
|
|
|
594
491
|
```js
|
|
595
|
-
|
|
596
|
-
|
|
492
|
+
const {createTest} = require('@putout/test');
|
|
493
|
+
const test = createTest({
|
|
494
|
+
'remove-debugger': plugin,
|
|
597
495
|
});
|
|
598
496
|
```
|
|
599
497
|
|
|
@@ -790,332 +688,305 @@ export const {
|
|
|
790
688
|
});
|
|
791
689
|
```
|
|
792
690
|
|
|
793
|
-
## apply-
|
|
691
|
+
## apply-for-of-to-track-file
|
|
692
|
+
|
|
693
|
+
> The **Generator** object is returned by a `generator function` and it conforms to both the iterable protocol and the `iterator` protocol.
|
|
694
|
+
>
|
|
695
|
+
> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator)
|
|
696
|
+
|
|
697
|
+
`trackFile` is generator function used to count progress that can be used in [**Scanner**](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#scanner).
|
|
698
|
+
|
|
699
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/5ec6c384aa6e4471aab17efb86e185f3/e749c7d649ef2da76410a5964e7c875d10538789)
|
|
794
700
|
|
|
795
701
|
### ❌ Example of incorrect code
|
|
796
702
|
|
|
797
703
|
```js
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
});
|
|
704
|
+
module.exports.scan = (path, {push, trackFile}) => {
|
|
705
|
+
trackFile(path, '*.swp').map(push);
|
|
706
|
+
};
|
|
802
707
|
```
|
|
803
708
|
|
|
804
709
|
### ✅ Example of correct code
|
|
805
710
|
|
|
806
711
|
```js
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
712
|
+
module.exports.scan = (path, {push, trackFile}) => {
|
|
713
|
+
for (const file of trackFile(path, '*.swp')) {
|
|
714
|
+
push(file);
|
|
715
|
+
}
|
|
716
|
+
};
|
|
810
717
|
```
|
|
811
718
|
|
|
812
|
-
## apply-
|
|
719
|
+
## apply-get-binding
|
|
720
|
+
|
|
721
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/6c82eac69034a1bb10405aec9d0c9df1/acc0ced44417671f1af60b84f4d9707c735365f0).
|
|
813
722
|
|
|
814
723
|
### ❌ Example of incorrect code
|
|
815
724
|
|
|
816
725
|
```js
|
|
817
|
-
|
|
818
|
-
'remove-debugger': plugin,
|
|
819
|
-
});
|
|
726
|
+
path.scope.getBinding('require');
|
|
820
727
|
```
|
|
821
728
|
|
|
822
729
|
### ✅ Example of correct code
|
|
823
730
|
|
|
824
731
|
```js
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
const test = createTest({
|
|
828
|
-
'remove-debugger': plugin,
|
|
829
|
-
});
|
|
732
|
+
getBinding(path, 'require');
|
|
830
733
|
```
|
|
831
734
|
|
|
832
|
-
## apply-
|
|
735
|
+
## apply-insert-after
|
|
833
736
|
|
|
834
|
-
|
|
737
|
+
Better to use [`insertAfter(a, b)`](https://github.com/coderaiser/putout/tree/master/packages/operate#insert-after) method of `operator`.
|
|
738
|
+
It helps to avoid duplication of comments.
|
|
835
739
|
|
|
836
740
|
### ❌ Example of incorrect code
|
|
837
741
|
|
|
838
742
|
```js
|
|
839
|
-
const
|
|
840
|
-
|
|
743
|
+
export const fix = (path) => {
|
|
744
|
+
path.insertAfter(path.get('init'));
|
|
745
|
+
};
|
|
841
746
|
```
|
|
842
747
|
|
|
843
748
|
### ✅ Example of correct code
|
|
844
749
|
|
|
845
750
|
```js
|
|
846
|
-
|
|
847
|
-
|
|
751
|
+
import {operator} from 'putout';
|
|
752
|
+
|
|
753
|
+
const {insertAfter} = operator;
|
|
754
|
+
|
|
755
|
+
export const fix = (path) => {
|
|
756
|
+
insertAfter(path, path.get('init'));
|
|
757
|
+
};
|
|
848
758
|
```
|
|
849
759
|
|
|
850
|
-
## apply-
|
|
760
|
+
## apply-insert-before
|
|
851
761
|
|
|
852
|
-
|
|
762
|
+
Better to use [`insertBefore(a, b)`](https://github.com/coderaiser/putout/tree/master/packages/operate#insert-before) method of `operator`.
|
|
853
763
|
|
|
854
764
|
### ❌ Example of incorrect code
|
|
855
765
|
|
|
856
766
|
```js
|
|
857
|
-
|
|
767
|
+
export const fix = (path) => {
|
|
768
|
+
path.insertBefore(path.get('init'));
|
|
769
|
+
};
|
|
858
770
|
```
|
|
859
771
|
|
|
860
772
|
### ✅ Example of correct code
|
|
861
773
|
|
|
862
774
|
```js
|
|
863
|
-
import
|
|
864
|
-
```
|
|
775
|
+
import {operator} from 'putout';
|
|
865
776
|
|
|
866
|
-
|
|
777
|
+
const {insertBefore} = operator;
|
|
867
778
|
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
779
|
+
export const fix = (path) => {
|
|
780
|
+
insertBefore(path, path.get('init'));
|
|
781
|
+
};
|
|
782
|
+
```
|
|
871
783
|
|
|
872
|
-
|
|
784
|
+
## apply-lowercase-to-node-builders
|
|
873
785
|
|
|
874
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/
|
|
786
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/fe78f6e48998fb39fa7e53e4046f1fc0/e1e6f2387895ff2ab98b4a9bcd2e8d565f7c3f16).
|
|
875
787
|
|
|
876
788
|
### ❌ Example of incorrect code
|
|
877
789
|
|
|
878
790
|
```js
|
|
879
|
-
|
|
880
|
-
trackFile(path, '*.swp').map(push);
|
|
881
|
-
};
|
|
791
|
+
path.node = Identifier('x');
|
|
882
792
|
```
|
|
883
793
|
|
|
884
794
|
### ✅ Example of correct code
|
|
885
795
|
|
|
886
796
|
```js
|
|
887
|
-
|
|
888
|
-
for (const file of trackFile(path, '*.swp')) {
|
|
889
|
-
push(file);
|
|
890
|
-
}
|
|
891
|
-
};
|
|
797
|
+
path.node = identifier('x');
|
|
892
798
|
```
|
|
893
799
|
|
|
894
|
-
##
|
|
895
|
-
|
|
896
|
-
Add properties to `createTest` options, here is example of `.putout.json`:
|
|
897
|
-
|
|
898
|
-
```json
|
|
899
|
-
{
|
|
900
|
-
"rules": {
|
|
901
|
-
"putout/create-test": ["on", {
|
|
902
|
-
"add": [
|
|
903
|
-
["printer", "putout"]
|
|
904
|
-
]
|
|
905
|
-
}]
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
```
|
|
800
|
+
## apply-name-to-is-identifier
|
|
909
801
|
|
|
910
|
-
|
|
802
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/9d416e21377a53ef13066007f7037bdf/e179718fe1908851c26f10ba84fab1bf7ebca3ce).
|
|
911
803
|
|
|
912
804
|
### ❌ Example of incorrect code
|
|
913
805
|
|
|
914
806
|
```js
|
|
915
|
-
|
|
916
|
-
'putout/create-test': plugin,
|
|
917
|
-
});
|
|
807
|
+
isIdentifier(path, 'hello');
|
|
918
808
|
```
|
|
919
809
|
|
|
920
810
|
### ✅ Example of correct code
|
|
921
811
|
|
|
922
812
|
```js
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
plugins: [
|
|
926
|
-
['putout/create-test', plugin],
|
|
927
|
-
],
|
|
813
|
+
isIdentifier(path, {
|
|
814
|
+
name: 'hello',
|
|
928
815
|
});
|
|
929
816
|
```
|
|
930
817
|
|
|
931
|
-
##
|
|
818
|
+
## apply-namespace-specifier
|
|
932
819
|
|
|
933
|
-
|
|
820
|
+
Most likely what you need is [`esm/resolve-imported-file`](https://github.com/coderaiser/putout/tree/master/packages/plugin-esm#resolve-imported-file).
|
|
934
821
|
|
|
935
822
|
### ❌ Example of incorrect code
|
|
936
823
|
|
|
937
824
|
```js
|
|
938
|
-
|
|
939
|
-
isNumberLiteral(node);
|
|
825
|
+
import rmUnused from '@putout/plugin-remove-unused-variables';
|
|
940
826
|
```
|
|
941
827
|
|
|
942
828
|
### ✅ Example of correct code
|
|
943
829
|
|
|
944
830
|
```js
|
|
945
|
-
|
|
946
|
-
isNumericLiteral(node);
|
|
947
|
-
```
|
|
948
|
-
|
|
949
|
-
## convert-putout-test-to-create-test
|
|
950
|
-
|
|
951
|
-
Fixes results of [@putout/convert-commonjs-to-esm](https://github.com/coderaiser/putout/tree/master/packages/plugin-convert-commonjs-to-esm#readme) work.
|
|
952
|
-
|
|
953
|
-
### ❌ Example of incorrect code
|
|
954
|
-
|
|
955
|
-
```js
|
|
956
|
-
import putoutTest from '@putout/test';
|
|
957
|
-
|
|
958
|
-
const test = putoutTest(__dirname, {
|
|
959
|
-
'remove-unused-variables': rmVars,
|
|
960
|
-
});
|
|
831
|
+
import * as rmUnused from '@putout/plugin-remove-unused-variables';
|
|
961
832
|
```
|
|
962
833
|
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
```js
|
|
966
|
-
import {createTest} from '@putout/test';
|
|
834
|
+
## apply-parens
|
|
967
835
|
|
|
968
|
-
|
|
969
|
-
'remove-unused-variables': rmVars,
|
|
970
|
-
});
|
|
971
|
-
```
|
|
836
|
+
Better use [`addParens(path)`](https://github.com/coderaiser/putout/tree/master/packages/operate#addparenspath-path) method of `operator` instead of using `path.node.extra` to have support of both printers:
|
|
972
837
|
|
|
973
|
-
|
|
838
|
+
- ✅ `@putout/printer`;
|
|
839
|
+
- ✅ `babel`;
|
|
974
840
|
|
|
975
|
-
|
|
841
|
+
Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d325a84e26807d46b5ec14db179c38f4/8bcd22d6dbe880c0fd70992a1a36b9c609b53b22).
|
|
976
842
|
|
|
977
843
|
### ❌ Example of incorrect code
|
|
978
844
|
|
|
979
845
|
```js
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
846
|
+
path.node.extra.parenthesized = false;
|
|
847
|
+
path.node.extra.parenthesized = true;
|
|
848
|
+
|
|
849
|
+
if (!path.node.extra?.parenthesized)
|
|
850
|
+
return;
|
|
984
851
|
```
|
|
985
852
|
|
|
986
853
|
### ✅ Example of correct code
|
|
987
854
|
|
|
988
855
|
```js
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
['convert-do-while-to-jnz', convertDoWhileToJnz],
|
|
992
|
-
]);
|
|
993
|
-
```
|
|
856
|
+
removeParens(path);
|
|
857
|
+
addParens(path);
|
|
994
858
|
|
|
995
|
-
|
|
859
|
+
if (!hasParens(path))
|
|
860
|
+
return;
|
|
861
|
+
```
|
|
996
862
|
|
|
997
|
-
|
|
863
|
+
## apply-processors-destructuring
|
|
998
864
|
|
|
999
865
|
### ❌ Example of incorrect code
|
|
1000
866
|
|
|
1001
867
|
```js
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
};
|
|
1005
|
-
|
|
1006
|
-
push({
|
|
1007
|
-
path: child,
|
|
868
|
+
test('', async (t) => {
|
|
869
|
+
await t.process({});
|
|
1008
870
|
});
|
|
1009
871
|
```
|
|
1010
872
|
|
|
1011
873
|
### ✅ Example of correct code
|
|
1012
874
|
|
|
1013
875
|
```js
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
};
|
|
1017
|
-
|
|
1018
|
-
push(child);
|
|
876
|
+
test('', async ({process}) => {
|
|
877
|
+
await process({});
|
|
878
|
+
});
|
|
1019
879
|
```
|
|
1020
880
|
|
|
1021
|
-
##
|
|
881
|
+
## apply-processors-destructuring
|
|
1022
882
|
|
|
1023
883
|
### ❌ Example of incorrect code
|
|
1024
884
|
|
|
1025
885
|
```js
|
|
1026
|
-
test('
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
t.transform(code, '');
|
|
1030
|
-
t.end();
|
|
886
|
+
test('', async (t) => {
|
|
887
|
+
await t.process({});
|
|
1031
888
|
});
|
|
1032
889
|
```
|
|
1033
890
|
|
|
1034
891
|
### ✅ Example of correct code
|
|
1035
892
|
|
|
1036
893
|
```js
|
|
1037
|
-
test('
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
t.noTransformCode(code);
|
|
1041
|
-
t.end();
|
|
894
|
+
test('', async ({process}) => {
|
|
895
|
+
await process({});
|
|
1042
896
|
});
|
|
1043
897
|
```
|
|
1044
898
|
|
|
1045
|
-
##
|
|
899
|
+
## apply-remove
|
|
900
|
+
|
|
901
|
+
Better to use [`remove(path)`](https://github.com/coderaiser/putout/tree/master/packages/operate#removepath) method of `operator`.
|
|
902
|
+
It helps to preserve comments.
|
|
1046
903
|
|
|
1047
904
|
### ❌ Example of incorrect code
|
|
1048
905
|
|
|
1049
906
|
```js
|
|
1050
|
-
|
|
1051
|
-
path.
|
|
907
|
+
export const fix = (path) => {
|
|
908
|
+
path.remove();
|
|
1052
909
|
};
|
|
1053
910
|
```
|
|
1054
911
|
|
|
1055
912
|
### ✅ Example of correct code
|
|
1056
913
|
|
|
1057
914
|
```js
|
|
1058
|
-
|
|
915
|
+
import {operator} from 'putout';
|
|
1059
916
|
|
|
1060
|
-
|
|
1061
|
-
|
|
917
|
+
const {remove} = operator;
|
|
918
|
+
|
|
919
|
+
export const fix = (path) => {
|
|
920
|
+
remove(path);
|
|
1062
921
|
};
|
|
1063
922
|
```
|
|
1064
923
|
|
|
1065
|
-
##
|
|
924
|
+
## apply-rename
|
|
925
|
+
|
|
926
|
+
Better use [`rename(path, from, to)`](https://github.com/coderaiser/putout/tree/master/packages/operate#rename) method of `operator`.
|
|
927
|
+
Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/22716f61af86351331fc92260b7ed8e6/1435f31954764c119813e03654caa36e6a2a666b).
|
|
1066
928
|
|
|
1067
929
|
### ❌ Example of incorrect code
|
|
1068
930
|
|
|
1069
931
|
```js
|
|
1070
|
-
|
|
1071
|
-
path.
|
|
1072
|
-
identifier('hello'),
|
|
1073
|
-
]);
|
|
932
|
+
export const fix = ({path, from, to}) => {
|
|
933
|
+
path.scope.rename(from, to);
|
|
1074
934
|
};
|
|
1075
935
|
```
|
|
1076
936
|
|
|
1077
937
|
### ✅ Example of correct code
|
|
1078
938
|
|
|
1079
939
|
```js
|
|
1080
|
-
|
|
940
|
+
import {operator} from 'putout';
|
|
1081
941
|
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
942
|
+
const {rename} = operator;
|
|
943
|
+
|
|
944
|
+
export const fix = ({path, from, to}) => {
|
|
945
|
+
rename(path, from, to);
|
|
1086
946
|
};
|
|
1087
947
|
```
|
|
1088
948
|
|
|
1089
|
-
##
|
|
949
|
+
## apply-report
|
|
950
|
+
|
|
951
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e9debc0b256556a632fb031be86afffc/afefbd44443f07dbb7d8f2972f2e40a9a82c214f).
|
|
1090
952
|
|
|
1091
953
|
### ❌ Example of incorrect code
|
|
1092
954
|
|
|
1093
955
|
```js
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
956
|
+
t.noReport('rename-files-full', {
|
|
957
|
+
from: ['/'],
|
|
958
|
+
to: [],
|
|
959
|
+
});
|
|
960
|
+
t.noReportWithOptions('rename-files-full');
|
|
961
|
+
t.noReport('a', 'Use b');
|
|
962
|
+
t.report('a');
|
|
1097
963
|
```
|
|
1098
964
|
|
|
1099
965
|
### ✅ Example of correct code
|
|
1100
966
|
|
|
1101
967
|
```js
|
|
1102
|
-
|
|
1103
|
-
|
|
968
|
+
t.noReportWithOptions('rename-files-full', {
|
|
969
|
+
from: ['/'],
|
|
970
|
+
to: [],
|
|
1104
971
|
});
|
|
972
|
+
t.noReport('rename-files-full');
|
|
973
|
+
t.report('a', 'Use b');
|
|
974
|
+
t.noReport('a');
|
|
1105
975
|
```
|
|
1106
976
|
|
|
1107
|
-
##
|
|
977
|
+
## apply-short-processors
|
|
1108
978
|
|
|
1109
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/
|
|
979
|
+
Apply short names of processors, for example `__json` instead of `__putout_processor_json` . Checkout out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/908151edd3ee8d6a07d589df1e863883/1bd1eeadadea40915a2079f33a3845fa4fedda8e).
|
|
1110
980
|
|
|
1111
981
|
### ❌ Example of incorrect code
|
|
1112
982
|
|
|
1113
983
|
```js
|
|
1114
|
-
export const
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
984
|
+
export const match = () => ({
|
|
985
|
+
'__putout_processor_ignore(__a)': ({__a}) => {
|
|
986
|
+
const list = __a.elements.map(getValue);
|
|
987
|
+
},
|
|
988
|
+
'__putout_processor_filesystem(__a)': ({__a}) => {
|
|
989
|
+
const list = __a.elements.map(getValue);
|
|
1119
990
|
},
|
|
1120
991
|
});
|
|
1121
992
|
```
|
|
@@ -1123,131 +994,200 @@ export const replace = () => ({
|
|
|
1123
994
|
### ✅ Example of correct code
|
|
1124
995
|
|
|
1125
996
|
```js
|
|
1126
|
-
export const
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
997
|
+
export const match = () => ({
|
|
998
|
+
[__ignore]: ({__array}) => {
|
|
999
|
+
const list = __array.elements.map(getValue);
|
|
1000
|
+
},
|
|
1001
|
+
[__filesystem]: ({__object}) => {
|
|
1002
|
+
const list = __object.elements.map(getValue);
|
|
1131
1003
|
},
|
|
1132
1004
|
});
|
|
1133
1005
|
```
|
|
1134
1006
|
|
|
1135
|
-
##
|
|
1007
|
+
## apply-string-to-property-key
|
|
1008
|
+
|
|
1009
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/46e3930cbdf32d316c0c6cb21eb59f5a/aecd754638d0bac8252048a4f4b3131c15ef6c6f).
|
|
1136
1010
|
|
|
1137
1011
|
### ❌ Example of incorrect code
|
|
1138
1012
|
|
|
1139
1013
|
```js
|
|
1140
|
-
|
|
1141
|
-
'
|
|
1014
|
+
export const replace = {
|
|
1015
|
+
[`section('@select', select(__args))`]: ({__args}, path) => {
|
|
1016
|
+
__args.unshift(identifier('id'));
|
|
1017
|
+
return path;
|
|
1018
|
+
},
|
|
1142
1019
|
};
|
|
1143
1020
|
```
|
|
1144
1021
|
|
|
1145
1022
|
### ✅ Example of correct code
|
|
1146
1023
|
|
|
1147
1024
|
```js
|
|
1148
|
-
|
|
1149
|
-
'
|
|
1150
|
-
|
|
1025
|
+
export const replace = {
|
|
1026
|
+
'section("@select", select(__args))"': ({__args}, path) => {
|
|
1027
|
+
__args.unshift(identifier('id'));
|
|
1028
|
+
return path;
|
|
1029
|
+
},
|
|
1030
|
+
};
|
|
1151
1031
|
```
|
|
1152
1032
|
|
|
1153
|
-
##
|
|
1033
|
+
## apply-transform-with-options
|
|
1034
|
+
|
|
1035
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/92d40d40c75481816a5b5507e01d8315/bb54e932b4fff4bc0b453d723c72c7a9ed796b98).
|
|
1154
1036
|
|
|
1155
1037
|
### ❌ Example of incorrect code
|
|
1156
1038
|
|
|
1157
1039
|
```js
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
isIdentifier,
|
|
1163
|
-
} = require('@babel/types');
|
|
1040
|
+
t.transform('submenu', {
|
|
1041
|
+
submenuIndex: 1,
|
|
1042
|
+
insideSubmenu: true,
|
|
1043
|
+
});
|
|
1164
1044
|
```
|
|
1165
1045
|
|
|
1166
1046
|
### ✅ Example of correct code
|
|
1167
1047
|
|
|
1168
1048
|
```js
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
isIdentifier,
|
|
1174
|
-
} = require('putout').types;
|
|
1049
|
+
t.transformWithOptions('submenu', {
|
|
1050
|
+
submenuIndex: 1,
|
|
1051
|
+
insideSubmenu: true,
|
|
1052
|
+
});
|
|
1175
1053
|
```
|
|
1176
1054
|
|
|
1177
|
-
##
|
|
1055
|
+
## apply-traverser-to-ignore
|
|
1056
|
+
|
|
1057
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/ff74cf775696df17a5ba96c7ec309821/1cbdee25af883ccefd0a3614fe8424d8690fc58a).
|
|
1178
1058
|
|
|
1179
1059
|
### ❌ Example of incorrect code
|
|
1180
1060
|
|
|
1181
1061
|
```js
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1062
|
+
export const {
|
|
1063
|
+
report,
|
|
1064
|
+
match,
|
|
1065
|
+
replace,
|
|
1066
|
+
} = ignore({
|
|
1067
|
+
type: __json,
|
|
1068
|
+
name: '.nycrc.json',
|
|
1069
|
+
field: 'exclude',
|
|
1070
|
+
list: ['*.config.*'],
|
|
1185
1071
|
});
|
|
1186
1072
|
```
|
|
1187
1073
|
|
|
1188
1074
|
### ✅ Example of correct code
|
|
1189
1075
|
|
|
1190
1076
|
```js
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1077
|
+
export const {
|
|
1078
|
+
report,
|
|
1079
|
+
fix,
|
|
1080
|
+
traverse,
|
|
1081
|
+
} = ignore({
|
|
1082
|
+
type: __json,
|
|
1083
|
+
name: '.nycrc.json',
|
|
1084
|
+
field: 'exclude',
|
|
1085
|
+
list: ['*.config.*'],
|
|
1086
|
+
});
|
|
1087
|
+
```
|
|
1088
|
+
|
|
1089
|
+
## apply-vars
|
|
1090
|
+
|
|
1091
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/6b1a4b5dc75f2591faf580774d23b38f/7278945371ceb76942494f7caf88375d2eaca869).
|
|
1198
1092
|
|
|
1199
1093
|
### ❌ Example of incorrect code
|
|
1200
1094
|
|
|
1201
1095
|
```js
|
|
1202
|
-
const
|
|
1096
|
+
export const replace = () => ({
|
|
1097
|
+
'__a(__args': ({}, path) => {
|
|
1098
|
+
return true;
|
|
1099
|
+
},
|
|
1100
|
+
});
|
|
1101
|
+
export const match = () => ({
|
|
1102
|
+
'__a(__args': ({}, path) => {
|
|
1103
|
+
return '';
|
|
1104
|
+
},
|
|
1105
|
+
});
|
|
1203
1106
|
```
|
|
1204
1107
|
|
|
1205
1108
|
### ✅ Example of correct code
|
|
1206
1109
|
|
|
1207
1110
|
```js
|
|
1208
|
-
const
|
|
1111
|
+
export const replace = () => ({
|
|
1112
|
+
'__a(__args': (vars, path) => {
|
|
1113
|
+
return true;
|
|
1114
|
+
},
|
|
1115
|
+
});
|
|
1116
|
+
export const match = () => ({
|
|
1117
|
+
'__a(__args': (vars, path) => {
|
|
1118
|
+
return '';
|
|
1119
|
+
},
|
|
1120
|
+
});
|
|
1209
1121
|
```
|
|
1210
1122
|
|
|
1211
|
-
##
|
|
1123
|
+
## check-declare
|
|
1124
|
+
|
|
1125
|
+
Checks that [Declarator](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#declarator) transform is possible.
|
|
1126
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/9fccb187bb8933afff0dc0db57b3cea8/25cb812978fadb4efb5f0cb44058a61f70f8b78e):
|
|
1212
1127
|
|
|
1213
1128
|
### ❌ Example of incorrect code
|
|
1214
1129
|
|
|
1215
1130
|
```js
|
|
1216
|
-
const
|
|
1131
|
+
export const match = () => ({
|
|
1132
|
+
'nemesis.getChar()': () => {
|
|
1133
|
+
return path.parentPath.isExpressionStatement();
|
|
1134
|
+
},
|
|
1135
|
+
'getChar()': ({__a}) => {
|
|
1136
|
+
return path.parentPath.isExpressionStatement();
|
|
1137
|
+
},
|
|
1138
|
+
});
|
|
1217
1139
|
```
|
|
1218
1140
|
|
|
1219
1141
|
### ✅ Example of correct code
|
|
1220
1142
|
|
|
1221
1143
|
```js
|
|
1222
|
-
const
|
|
1144
|
+
export const match = () => ({
|
|
1145
|
+
'nemesis.getChar()': (vars, path) => {
|
|
1146
|
+
return path.parentPath.isExpressionStatement();
|
|
1147
|
+
},
|
|
1148
|
+
'getChar()': ({__a}, path) => {
|
|
1149
|
+
return path.parentPath.isExpressionStatement();
|
|
1150
|
+
},
|
|
1151
|
+
});
|
|
1223
1152
|
```
|
|
1224
1153
|
|
|
1225
|
-
##
|
|
1226
|
-
|
|
1227
|
-
Checkout in 🐊**Putout Editor**:
|
|
1154
|
+
## check-match
|
|
1228
1155
|
|
|
1229
|
-
|
|
1230
|
-
|
|
1156
|
+
Checks that [Replacer](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#replacer) `match()` keys exists in `replace`.
|
|
1157
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/c245bee6b129614b2f68c2e89fc3b101/d9f935ccd7f41ff166111cd62277f3244b1d526e).
|
|
1231
1158
|
|
|
1232
1159
|
### ❌ Example of incorrect code
|
|
1233
1160
|
|
|
1234
|
-
```
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1161
|
+
```js
|
|
1162
|
+
export const scan = (root, {trackFile}) => {
|
|
1163
|
+
for (const file of trackFile(root, names)) {
|
|
1164
|
+
push(file);
|
|
1165
|
+
}
|
|
1166
|
+
};
|
|
1240
1167
|
```
|
|
1241
1168
|
|
|
1242
|
-
|
|
1169
|
+
### ✅ Example of correct code
|
|
1243
1170
|
|
|
1244
|
-
|
|
1171
|
+
```js
|
|
1172
|
+
export const scan = (root, {trackFile, push}) => {
|
|
1173
|
+
for (const file of trackFile(root, names)) {
|
|
1174
|
+
push(file);
|
|
1175
|
+
}
|
|
1176
|
+
};
|
|
1177
|
+
```
|
|
1178
|
+
|
|
1179
|
+
## check-replace-code
|
|
1180
|
+
|
|
1181
|
+
Checks that [Replacer](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#replacer) transform is possible.
|
|
1182
|
+
Pass `once=false` to always fail no matter how many `fixCounts` passed.
|
|
1245
1183
|
|
|
1246
1184
|
### ❌ Example of incorrect code
|
|
1247
1185
|
|
|
1248
1186
|
```js
|
|
1249
|
-
export const
|
|
1250
|
-
|
|
1187
|
+
export const traverse = () => ({
|
|
1188
|
+
TSUnionType() {
|
|
1189
|
+
console.log(path);
|
|
1190
|
+
},
|
|
1251
1191
|
});
|
|
1252
1192
|
```
|
|
1253
1193
|
|
|
@@ -1255,98 +1195,97 @@ export const include = () => ({
|
|
|
1255
1195
|
|
|
1256
1196
|
```js
|
|
1257
1197
|
export const traverse = () => ({
|
|
1258
|
-
|
|
1198
|
+
TSUnionType(path) {
|
|
1199
|
+
console.log(path);
|
|
1200
|
+
},
|
|
1259
1201
|
});
|
|
1260
1202
|
```
|
|
1261
1203
|
|
|
1262
|
-
## convert-
|
|
1204
|
+
## convert-add-argument-to-add-args
|
|
1263
1205
|
|
|
1264
1206
|
### ❌ Example of incorrect code
|
|
1265
1207
|
|
|
1266
1208
|
```js
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
push(path);
|
|
1270
|
-
},
|
|
1209
|
+
test('', () => {
|
|
1210
|
+
comparePlaces();
|
|
1271
1211
|
});
|
|
1272
1212
|
```
|
|
1273
1213
|
|
|
1274
1214
|
### ✅ Example of correct code
|
|
1275
1215
|
|
|
1276
1216
|
```js
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1217
|
+
test('', ({comparePlaces}) => {
|
|
1218
|
+
comparePlaces();
|
|
1219
|
+
});
|
|
1280
1220
|
```
|
|
1281
1221
|
|
|
1282
|
-
## convert-
|
|
1222
|
+
## convert-babel-types
|
|
1283
1223
|
|
|
1284
|
-
|
|
1224
|
+
### ❌ Example of incorrect code
|
|
1225
|
+
|
|
1226
|
+
```js
|
|
1227
|
+
module.exports.preProcess = () => {};
|
|
1228
|
+
module.exports.postProcess = () => {};
|
|
1229
|
+
```
|
|
1230
|
+
|
|
1231
|
+
### ✅ Example of correct code
|
|
1232
|
+
|
|
1233
|
+
```js
|
|
1234
|
+
module.exports.branch = (rawSource) => [];
|
|
1235
|
+
module.exports.merge = (processedSource, list) => '';
|
|
1236
|
+
```
|
|
1237
|
+
|
|
1238
|
+
## convert-destructuring-to-identifier
|
|
1285
1239
|
|
|
1286
1240
|
### ❌ Example of incorrect code
|
|
1287
1241
|
|
|
1288
1242
|
```js
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
traverse();
|
|
1292
|
-
},
|
|
1243
|
+
module.exports.match = () => ({
|
|
1244
|
+
'module.exports.traverse = __a'({}, path) {},
|
|
1293
1245
|
});
|
|
1294
1246
|
```
|
|
1295
1247
|
|
|
1296
1248
|
### ✅ Example of correct code
|
|
1297
1249
|
|
|
1298
1250
|
```js
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
superTraverse(path, {
|
|
1302
|
-
'__a(__b, __c)': (path) => {},
|
|
1303
|
-
});
|
|
1304
|
-
},
|
|
1251
|
+
module.exports.match = () => ({
|
|
1252
|
+
'module.exports.traverse = __a': ({}, path) => {},
|
|
1305
1253
|
});
|
|
1306
1254
|
```
|
|
1307
1255
|
|
|
1308
|
-
## convert-
|
|
1256
|
+
## convert-dirname-to-url
|
|
1309
1257
|
|
|
1310
1258
|
### ❌ Example of incorrect code
|
|
1311
1259
|
|
|
1312
1260
|
```js
|
|
1313
1261
|
module.exports.traverse = () => ({
|
|
1314
|
-
'
|
|
1262
|
+
'__a.replace(/__b/g, __c)': (path) => {
|
|
1263
|
+
push(path);
|
|
1264
|
+
},
|
|
1315
1265
|
});
|
|
1316
1266
|
```
|
|
1317
1267
|
|
|
1318
1268
|
### ✅ Example of correct code
|
|
1319
1269
|
|
|
1320
1270
|
```js
|
|
1321
|
-
module.exports.
|
|
1322
|
-
'
|
|
1271
|
+
module.exports.traverse = ({push}) => ({
|
|
1272
|
+
'__a.replace(/__b/g, __c)': (path) => {
|
|
1273
|
+
push(path);
|
|
1274
|
+
},
|
|
1323
1275
|
});
|
|
1324
1276
|
```
|
|
1325
1277
|
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
Checkout in 🐊**Putout Editor**:
|
|
1329
|
-
|
|
1330
|
-
- [`Traverser`](https://putout.cloudcmd.io/#/gist/afe988c8e53ae70e50bf26512672f3cd/a6677d53b996e85880a4af18250c00e849322bbe);
|
|
1331
|
-
- [`Replacer`](https://putout.cloudcmd.io/#/gist/2e89f498c88f3208beeb85dd01a9178e/ed975281c57f451fc1c3aaf187425a33499af71d);
|
|
1278
|
+
- [`store`](https://github.com/coderaiser/putout/blob/master/packages/engine-runner/README.md#store)
|
|
1332
1279
|
|
|
1333
1280
|
### ❌ Example of incorrect code
|
|
1334
1281
|
|
|
1335
1282
|
```js
|
|
1336
|
-
module.exports.traverse = (
|
|
1337
|
-
|
|
1338
|
-
const {
|
|
1283
|
+
module.exports.traverse = () => ({
|
|
1284
|
+
ImportDeclaration(path) {
|
|
1285
|
+
const {node} = path;
|
|
1286
|
+
const {name} = node.specifiers[0].local;
|
|
1339
1287
|
|
|
1340
|
-
|
|
1341
|
-
const files = findFile(path, name);
|
|
1342
|
-
|
|
1343
|
-
for (const file of files) {
|
|
1344
|
-
push({
|
|
1345
|
-
name,
|
|
1346
|
-
path: file,
|
|
1347
|
-
});
|
|
1348
|
-
}
|
|
1349
|
-
}
|
|
1288
|
+
store('name', name);
|
|
1350
1289
|
},
|
|
1351
1290
|
});
|
|
1352
1291
|
```
|
|
@@ -1354,211 +1293,242 @@ module.exports.traverse = ({push, options}) => ({
|
|
|
1354
1293
|
### ✅ Example of correct code
|
|
1355
1294
|
|
|
1356
1295
|
```js
|
|
1357
|
-
module.exports.
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
const files = findFile(path, name);
|
|
1296
|
+
module.exports.traverse = ({store}) => ({
|
|
1297
|
+
ImportDeclaration(path) {
|
|
1298
|
+
const {node} = path;
|
|
1299
|
+
const {name} = node.specifiers[0].local;
|
|
1362
1300
|
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
});
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
};
|
|
1301
|
+
store('name', name);
|
|
1302
|
+
},
|
|
1303
|
+
});
|
|
1370
1304
|
```
|
|
1371
1305
|
|
|
1372
|
-
|
|
1306
|
+
- [`listStore``](https://github.com/coderaiser/putout/blob/master/packages/engine-runner/README.md#liststore)
|
|
1373
1307
|
|
|
1374
1308
|
### ❌ Example of incorrect code
|
|
1375
1309
|
|
|
1376
1310
|
```js
|
|
1377
|
-
|
|
1378
|
-
|
|
1311
|
+
export const traverse = () => ({
|
|
1312
|
+
ImportDeclaration(path) {
|
|
1313
|
+
listStore(path);
|
|
1314
|
+
},
|
|
1315
|
+
});
|
|
1379
1316
|
```
|
|
1380
1317
|
|
|
1381
1318
|
### ✅ Example of correct code
|
|
1382
1319
|
|
|
1383
1320
|
```js
|
|
1384
|
-
module.exports.
|
|
1385
|
-
|
|
1321
|
+
module.exports.traverse = ({listStore}) => ({
|
|
1322
|
+
ImportDeclaration(path) {
|
|
1323
|
+
listStore(path);
|
|
1324
|
+
},
|
|
1325
|
+
});
|
|
1386
1326
|
```
|
|
1387
1327
|
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
- property simpler to work with;
|
|
1391
|
-
- support of [`convert-destructuring-to-identifier`](#convert-destructuring-to-identifier) which is `Replacer`, while `convert-method-to-property` is `Includer` (searches for `ObjectMethod` node);
|
|
1328
|
+
- [`pathStore`](https://github.com/coderaiser/putout/blob/master/packages/engine-runner/README.md#pathstore)
|
|
1392
1329
|
|
|
1393
1330
|
### ❌ Example of incorrect code
|
|
1394
1331
|
|
|
1395
1332
|
```js
|
|
1396
|
-
|
|
1397
|
-
'module.exports.
|
|
1333
|
+
export const traverse = () => ({
|
|
1334
|
+
'module.exports.match = __object': pathStore,
|
|
1398
1335
|
});
|
|
1399
1336
|
```
|
|
1400
1337
|
|
|
1401
1338
|
### ✅ Example of correct code
|
|
1402
1339
|
|
|
1403
1340
|
```js
|
|
1404
|
-
|
|
1405
|
-
'module.exports.
|
|
1341
|
+
export const traverse = ({pathStore}) => ({
|
|
1342
|
+
'module.exports.match = __object': pathStore,
|
|
1406
1343
|
});
|
|
1407
1344
|
```
|
|
1408
1345
|
|
|
1409
|
-
##
|
|
1346
|
+
## convert-get-file-content-to-read-file-content
|
|
1410
1347
|
|
|
1411
|
-
|
|
1412
|
-
|
|
1348
|
+
To read file content use [`readFileContent`](https://github.com/coderaiser/putout/tree/master/packages/operator-filesystem#readfilecontentfilepath-filepath-string) and never confuse.
|
|
1349
|
+
|
|
1350
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/828da75f16a526652b138948d810ed9e/754bd02869a7e4e119e9fb442dab93df7785fb56).
|
|
1413
1351
|
|
|
1414
1352
|
### ❌ Example of incorrect code
|
|
1415
1353
|
|
|
1416
1354
|
```js
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1355
|
+
const {operator} = require('putout');
|
|
1356
|
+
const {addArgument} = operator;
|
|
1357
|
+
|
|
1358
|
+
module.exports = addArgument({
|
|
1359
|
+
t: ['t', 'test("__a", (__args) => __body)'],
|
|
1420
1360
|
});
|
|
1421
1361
|
```
|
|
1422
1362
|
|
|
1423
|
-
|
|
1424
|
-
This is additional tests, if you forget to test some case (from a big list of rules that is supported) it will be checked with this `rule` and make transforms more stable.*
|
|
1363
|
+
### ✅ Example of correct code
|
|
1425
1364
|
|
|
1426
|
-
|
|
1365
|
+
```js
|
|
1366
|
+
const {operator} = require('putout');
|
|
1367
|
+
const {addArgs} = operator;
|
|
1427
1368
|
|
|
1428
|
-
|
|
1429
|
-
|
|
1369
|
+
module.exports = addArgs({
|
|
1370
|
+
t: ['t', 'test("__a", (__args) => __body)'],
|
|
1371
|
+
});
|
|
1372
|
+
```
|
|
1373
|
+
|
|
1374
|
+
## convert-get-rule-to-require
|
|
1375
|
+
|
|
1376
|
+
- ✅ import [Nested plugins](https://github.com/coderaiser/putout/tree/master/packages/engine-loader#nested-plugin) in [**Deno** and **Browser**](https://github.com/putoutjs/bundle/);
|
|
1377
|
+
- ✅ easier bundle with rollup without [`dynamicRequireTargets`](https://github.com/rollup/plugins/tree/master/packages/commonjs/#dynamicrequiretargets);
|
|
1378
|
+
- ✅ easier to migrate to **ESM**;
|
|
1379
|
+
|
|
1380
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/38336fcc5b5ae6e441697e098067319c/dd98578c9554b7bd5dceee0499118f7d8216e1da).
|
|
1430
1381
|
|
|
1431
1382
|
### ❌ Example of incorrect code
|
|
1432
1383
|
|
|
1433
1384
|
```js
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
}
|
|
1385
|
+
export const scan = (root, {push, progress}) => {
|
|
1386
|
+
trackFile();
|
|
1387
|
+
};
|
|
1437
1388
|
```
|
|
1438
1389
|
|
|
1439
|
-
|
|
1440
|
-
This is additional tests, if you forget to test some case (from a big list of rules that is supported) it will be checked with this `rule` and make transforms more stable.*
|
|
1390
|
+
### ✅ Example of correct code
|
|
1441
1391
|
|
|
1442
|
-
|
|
1392
|
+
```js
|
|
1393
|
+
export const scan = (root, {push, progress, trackFile}) => {
|
|
1394
|
+
trackFile();
|
|
1395
|
+
};
|
|
1396
|
+
```
|
|
1443
1397
|
|
|
1444
|
-
|
|
1445
|
-
|
|
1398
|
+
## convert-include-to-traverse
|
|
1399
|
+
|
|
1400
|
+
Checkout in 🐊[**Putout Editor*](https://putout.cloudcmd.io/#/gist/a41b5c943a74b59a6c18f31fc6d31937/d79c6084f49b6444536840bc2fc1fba725ba83f8).
|
|
1446
1401
|
|
|
1447
1402
|
### ❌ Example of incorrect code
|
|
1448
1403
|
|
|
1449
1404
|
```js
|
|
1450
|
-
module.exports.match = () => ({
|
|
1451
|
-
'__a = __b': (vars, path) => {},
|
|
1452
|
-
});
|
|
1453
|
-
|
|
1454
1405
|
module.exports.replace = () => ({
|
|
1455
|
-
'__a =
|
|
1406
|
+
'if (__a = __b) __body': 'if (__a === "__b") __body',
|
|
1456
1407
|
});
|
|
1457
1408
|
```
|
|
1458
1409
|
|
|
1459
1410
|
☝️ *There is no `fix` for this rule, it used internally to be more confident about `test coverage`, because of declaration form, transforms cannon be checked by `nyc` and `c8`, and uncovered lines can find unfixable false positives when running on code.
|
|
1460
1411
|
This is additional tests, if you forget to test some case (from a big list of rules that is supported) it will be checked with this `rule` and make transforms more stable.*
|
|
1461
1412
|
|
|
1462
|
-
##
|
|
1413
|
+
## convert-match-to-function
|
|
1463
1414
|
|
|
1464
1415
|
### ❌ Example of incorrect code
|
|
1465
1416
|
|
|
1466
1417
|
```js
|
|
1467
|
-
|
|
1468
|
-
|
|
1418
|
+
module.exports.traverse = ({push, options}) => ({
|
|
1419
|
+
[__filesystem](path) {
|
|
1420
|
+
const {names} = options;
|
|
1421
|
+
|
|
1422
|
+
for (const name of names) {
|
|
1423
|
+
const files = findFile(path, name);
|
|
1424
|
+
|
|
1425
|
+
for (const file of files) {
|
|
1426
|
+
push({
|
|
1427
|
+
name,
|
|
1428
|
+
path: file,
|
|
1429
|
+
});
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
},
|
|
1433
|
+
});
|
|
1469
1434
|
```
|
|
1470
1435
|
|
|
1471
1436
|
### ✅ Example of correct code
|
|
1472
1437
|
|
|
1473
1438
|
```js
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
const
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1439
|
+
module.exports.scan = (path, {push, options}) => {
|
|
1440
|
+
const {names} = options;
|
|
1441
|
+
|
|
1442
|
+
for (const name of names) {
|
|
1443
|
+
const files = findFile(path, name);
|
|
1444
|
+
|
|
1445
|
+
for (const file of files) {
|
|
1446
|
+
push(file, {
|
|
1447
|
+
name,
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
};
|
|
1481
1452
|
```
|
|
1482
1453
|
|
|
1483
|
-
##
|
|
1454
|
+
## convert-method-to-property
|
|
1484
1455
|
|
|
1485
|
-
|
|
1456
|
+
- property simpler to work with;
|
|
1457
|
+
- support of [`convert-destructuring-to-identifier`](#convert-destructuring-to-identifier) which is `Replacer`, while `convert-method-to-property` is `Includer` (searches for `ObjectMethod` node);
|
|
1486
1458
|
|
|
1487
1459
|
### ❌ Example of incorrect code
|
|
1488
1460
|
|
|
1489
1461
|
```js
|
|
1490
|
-
export const
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
return __args[__a];
|
|
1495
|
-
},
|
|
1496
|
-
});
|
|
1462
|
+
export const filter = () => {
|
|
1463
|
+
return path.isStringLiteral();
|
|
1464
|
+
};
|
|
1497
1465
|
```
|
|
1498
1466
|
|
|
1499
1467
|
### ✅ Example of correct code
|
|
1500
1468
|
|
|
1501
1469
|
```js
|
|
1502
|
-
export const
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1470
|
+
export const filter = (path) => {
|
|
1471
|
+
return path.isStringLiteral();
|
|
1472
|
+
};
|
|
1473
|
+
```
|
|
1474
|
+
|
|
1475
|
+
## convert-node-to-path-in-get-template-values
|
|
1476
|
+
|
|
1477
|
+
### ❌ Example of incorrect code
|
|
1478
|
+
|
|
1479
|
+
```js
|
|
1480
|
+
module.exports.declare = () => ({
|
|
1481
|
+
isNumber: 'const isNumber = () => {}',
|
|
1482
|
+
isString: 'const isNumber = () => {}',
|
|
1508
1483
|
});
|
|
1509
1484
|
```
|
|
1510
1485
|
|
|
1511
|
-
|
|
1486
|
+
☝️ *There is no `fix` for this rule, it used internally to be more confident about `test coverage`, because of declaration form, transforms cannon be checked by `nyc` and `c8`, and uncovered lines can find unfixable false positives when running on code.
|
|
1487
|
+
This is additional tests, if you forget to test some case (from a big list of rules that is supported) it will be checked with this `rule` and make transforms more stable.*
|
|
1512
1488
|
|
|
1513
|
-
|
|
1489
|
+
## convert-number-to-numeric
|
|
1490
|
+
|
|
1491
|
+
Prevent `Babel` warning: `The node type NumberLiteral has been renamed to NumericLiteral`.
|
|
1514
1492
|
|
|
1515
1493
|
### ❌ Example of incorrect code
|
|
1516
1494
|
|
|
1517
1495
|
```js
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
},
|
|
1525
|
-
});
|
|
1496
|
+
const {
|
|
1497
|
+
ObjectExpression,
|
|
1498
|
+
SpreadElement,
|
|
1499
|
+
isObjectExpression,
|
|
1500
|
+
isIdentifier,
|
|
1501
|
+
} = require('@babel/types');
|
|
1526
1502
|
```
|
|
1527
1503
|
|
|
1528
1504
|
### ✅ Example of correct code
|
|
1529
1505
|
|
|
1530
1506
|
```js
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
},
|
|
1538
|
-
});
|
|
1507
|
+
const {
|
|
1508
|
+
ObjectExpression,
|
|
1509
|
+
SpreadElement,
|
|
1510
|
+
isObjectExpression,
|
|
1511
|
+
isIdentifier,
|
|
1512
|
+
} = require('putout').types;
|
|
1539
1513
|
```
|
|
1540
1514
|
|
|
1541
|
-
##
|
|
1542
|
-
|
|
1543
|
-
### ❌ Example of incorrect code
|
|
1515
|
+
## convert-plugins-element-to-tuple
|
|
1544
1516
|
|
|
1545
|
-
[
|
|
1517
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/abcc9f79469db69849b6d6efd3e85a8a/0536c9f780a0c9db2feed3be92299a22f06b9720).
|
|
1546
1518
|
|
|
1547
|
-
|
|
1519
|
+
### ❌ Example of incorrect code
|
|
1548
1520
|
|
|
1549
1521
|
```js
|
|
1550
|
-
|
|
1522
|
+
const {__a, __b} = getTemplateValues(path.node, 'const __a = __b');
|
|
1551
1523
|
```
|
|
1552
1524
|
|
|
1553
1525
|
### ✅ Example of correct code
|
|
1554
1526
|
|
|
1555
1527
|
```js
|
|
1556
|
-
|
|
1528
|
+
const {__a, __b} = getTemplateValues(path, 'const __a = __b');
|
|
1557
1529
|
```
|
|
1558
1530
|
|
|
1559
|
-
##
|
|
1560
|
-
|
|
1561
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/3d3fb6b8f5e5376cdd1674c9b19e0e27/4872f77e680a2fc443618f4bf5fae3ffab11046a).
|
|
1531
|
+
## convert-process-to-find
|
|
1562
1532
|
|
|
1563
1533
|
### ❌ Example of incorrect code
|
|
1564
1534
|
|
|
@@ -1576,66 +1546,52 @@ export const fix = (path) => {
|
|
|
1576
1546
|
};
|
|
1577
1547
|
```
|
|
1578
1548
|
|
|
1579
|
-
##
|
|
1549
|
+
## convert-push-object-to-push-path
|
|
1580
1550
|
|
|
1581
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/
|
|
1551
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/fc54c923cb3cc4095c3c1d84d7ae7982/7de8eace54c8068be4ec5954ad4dde6d52ec6ca6).
|
|
1582
1552
|
|
|
1583
1553
|
### ❌ Example of incorrect code
|
|
1584
1554
|
|
|
1585
1555
|
```js
|
|
1586
|
-
|
|
1587
|
-
return path.isStringLiteral();
|
|
1588
|
-
};
|
|
1556
|
+
const parseOptions = require('putout/lib/parse-options');
|
|
1589
1557
|
```
|
|
1590
1558
|
|
|
1591
1559
|
### ✅ Example of correct code
|
|
1592
1560
|
|
|
1593
1561
|
```js
|
|
1594
|
-
|
|
1595
|
-
return path.isStringLiteral();
|
|
1596
|
-
};
|
|
1562
|
+
const parseOptions = require('putout/parse-options');
|
|
1597
1563
|
```
|
|
1598
1564
|
|
|
1599
|
-
##
|
|
1565
|
+
## convert-putout-test-to-create-test
|
|
1600
1566
|
|
|
1601
|
-
|
|
1567
|
+
Fixes results of [@putout/convert-commonjs-to-esm](https://github.com/coderaiser/putout/tree/master/packages/plugin-convert-commonjs-to-esm#readme) work.
|
|
1602
1568
|
|
|
1603
1569
|
### ❌ Example of incorrect code
|
|
1604
1570
|
|
|
1605
1571
|
```js
|
|
1606
|
-
|
|
1607
|
-
'
|
|
1608
|
-
|
|
1609
|
-
},
|
|
1610
|
-
'getChar()': ({__a}) => {
|
|
1611
|
-
return path.parentPath.isExpressionStatement();
|
|
1612
|
-
},
|
|
1572
|
+
module.exports.replace = () => ({
|
|
1573
|
+
'const __a = __b': ({}) => {},
|
|
1574
|
+
'const __c = __d': ({}, path) => {},
|
|
1613
1575
|
});
|
|
1614
1576
|
```
|
|
1615
1577
|
|
|
1616
1578
|
### ✅ Example of correct code
|
|
1617
1579
|
|
|
1618
1580
|
```js
|
|
1619
|
-
|
|
1620
|
-
'
|
|
1621
|
-
|
|
1622
|
-
},
|
|
1623
|
-
'getChar()': ({__a}, path) => {
|
|
1624
|
-
return path.parentPath.isExpressionStatement();
|
|
1625
|
-
},
|
|
1581
|
+
module.exports.replace = () => ({
|
|
1582
|
+
'const __a = __b': (vars) => {},
|
|
1583
|
+
'const __c = __d': (vars, path) => {},
|
|
1626
1584
|
});
|
|
1627
1585
|
```
|
|
1628
1586
|
|
|
1629
|
-
##
|
|
1630
|
-
|
|
1631
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e20eb16668b2ebbceca1a03cde859e93/fee08d6dbb6aa4d835adacc8e9de4d994fd34848).
|
|
1587
|
+
## convert-replace-to-function
|
|
1632
1588
|
|
|
1633
1589
|
### ❌ Example of incorrect code
|
|
1634
1590
|
|
|
1635
1591
|
```js
|
|
1636
1592
|
export const traverse = () => ({
|
|
1637
|
-
|
|
1638
|
-
|
|
1593
|
+
[__markdown]: (path) => {
|
|
1594
|
+
traverse();
|
|
1639
1595
|
},
|
|
1640
1596
|
});
|
|
1641
1597
|
```
|
|
@@ -1644,92 +1600,78 @@ export const traverse = () => ({
|
|
|
1644
1600
|
|
|
1645
1601
|
```js
|
|
1646
1602
|
export const traverse = () => ({
|
|
1647
|
-
|
|
1648
|
-
|
|
1603
|
+
[__markdown]: (path) => {
|
|
1604
|
+
superTraverse(path, {
|
|
1605
|
+
'__a(__b, __c)': (path) => {},
|
|
1606
|
+
});
|
|
1649
1607
|
},
|
|
1650
1608
|
});
|
|
1651
1609
|
```
|
|
1652
1610
|
|
|
1653
|
-
## add-
|
|
1654
|
-
|
|
1655
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/cae7b14fa6be0fe50b134839bea1e544/37f9d161146dbe4f0497f852ba54161a759f7cbd).
|
|
1611
|
+
## add-places-to-compare-places"
|
|
1656
1612
|
|
|
1657
1613
|
### ❌ Example of incorrect code
|
|
1658
1614
|
|
|
1615
|
+
[`comparePlaces`](https://github.com/coderaiser/putout/tree/master/packages/test#compareplacesfilename-places-overrides) takes two or more arguments.
|
|
1616
|
+
|
|
1617
|
+
Checkout in 🐊[Putout Editor](https://putout.cloudcmd.io/#/gist/a83b1a6785bb01102451df4510333f42/a2439f7f44da56318d9a0e44b2602972811d9afb).
|
|
1618
|
+
|
|
1659
1619
|
```js
|
|
1660
|
-
|
|
1661
|
-
for (const file of trackFile(root, names)) {
|
|
1662
|
-
push(file);
|
|
1663
|
-
}
|
|
1664
|
-
};
|
|
1620
|
+
comparePlaces('hello');
|
|
1665
1621
|
```
|
|
1666
1622
|
|
|
1667
1623
|
### ✅ Example of correct code
|
|
1668
1624
|
|
|
1669
1625
|
```js
|
|
1670
|
-
|
|
1671
|
-
for (const file of trackFile(root, names)) {
|
|
1672
|
-
push(file);
|
|
1673
|
-
}
|
|
1674
|
-
};
|
|
1626
|
+
comparePlaces('hello', []);
|
|
1675
1627
|
```
|
|
1676
1628
|
|
|
1677
|
-
##
|
|
1629
|
+
## convert-replace-to-traverse
|
|
1630
|
+
|
|
1631
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/a87ab50e500cd3aee3099063a48c0e3f/8dee3919638062563c9b39886d8bb8581f5722f2).
|
|
1678
1632
|
|
|
1679
1633
|
### ❌ Example of incorrect code
|
|
1680
1634
|
|
|
1681
1635
|
```js
|
|
1682
|
-
|
|
1683
|
-
|
|
1636
|
+
module.exports.traverse = () => ({
|
|
1637
|
+
'async (__a) => __b': 'async ({process}) => __b',
|
|
1684
1638
|
});
|
|
1685
1639
|
```
|
|
1686
1640
|
|
|
1687
1641
|
### ✅ Example of correct code
|
|
1688
1642
|
|
|
1689
1643
|
```js
|
|
1690
|
-
|
|
1691
|
-
|
|
1644
|
+
module.exports.replace = () => ({
|
|
1645
|
+
'async (__a) => __b': 'async ({process}) => __b',
|
|
1692
1646
|
});
|
|
1693
1647
|
```
|
|
1694
1648
|
|
|
1695
|
-
##
|
|
1696
|
-
|
|
1697
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/b453bd78b8e9380da8b2f33dfb38b4e2/53b14f89eb88aa10c8e00ba1f0251976592e14ee).
|
|
1698
|
-
Supported args:
|
|
1699
|
-
|
|
1700
|
-
- `push`:
|
|
1649
|
+
## convert-replace-with
|
|
1701
1650
|
|
|
1702
1651
|
### ❌ Example of incorrect code
|
|
1703
1652
|
|
|
1704
1653
|
```js
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
push(path);
|
|
1708
|
-
},
|
|
1654
|
+
export const include = () => ({
|
|
1655
|
+
ClassDeclaration(path) {},
|
|
1709
1656
|
});
|
|
1710
1657
|
```
|
|
1711
1658
|
|
|
1712
1659
|
### ✅ Example of correct code
|
|
1713
1660
|
|
|
1714
1661
|
```js
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
push(path);
|
|
1718
|
-
},
|
|
1662
|
+
export const traverse = () => ({
|
|
1663
|
+
ClassDeclaration(path) {},
|
|
1719
1664
|
});
|
|
1720
1665
|
```
|
|
1721
1666
|
|
|
1722
|
-
|
|
1667
|
+
## convert-replace-with-multiple
|
|
1723
1668
|
|
|
1724
1669
|
### ❌ Example of incorrect code
|
|
1725
1670
|
|
|
1726
1671
|
```js
|
|
1727
|
-
module.exports.traverse = () => ({
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
const {name} = node.specifiers[0].local;
|
|
1731
|
-
|
|
1732
|
-
store('name', name);
|
|
1672
|
+
module.exports.traverse = ({push}) => ({
|
|
1673
|
+
TSTypeAssertion(path) {
|
|
1674
|
+
push(path);
|
|
1733
1675
|
},
|
|
1734
1676
|
});
|
|
1735
1677
|
```
|
|
@@ -1737,141 +1679,181 @@ module.exports.traverse = () => ({
|
|
|
1737
1679
|
### ✅ Example of correct code
|
|
1738
1680
|
|
|
1739
1681
|
```js
|
|
1740
|
-
module.exports.
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
const {name} = node.specifiers[0].local;
|
|
1744
|
-
|
|
1745
|
-
store('name', name);
|
|
1746
|
-
},
|
|
1747
|
-
});
|
|
1682
|
+
module.exports.include = () => [
|
|
1683
|
+
'TSTypeAssertion',
|
|
1684
|
+
];
|
|
1748
1685
|
```
|
|
1749
1686
|
|
|
1750
|
-
|
|
1687
|
+
## convert-report-to-function
|
|
1751
1688
|
|
|
1752
1689
|
### ❌ Example of incorrect code
|
|
1753
1690
|
|
|
1754
1691
|
```js
|
|
1755
|
-
export const
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
},
|
|
1759
|
-
});
|
|
1692
|
+
export const scan = (root, {push, progress}) => {
|
|
1693
|
+
crawlFile();
|
|
1694
|
+
};
|
|
1760
1695
|
```
|
|
1761
1696
|
|
|
1762
1697
|
### ✅ Example of correct code
|
|
1763
1698
|
|
|
1764
1699
|
```js
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1700
|
+
export const scan = (root, {push, progress, crawlFile}) => {
|
|
1701
|
+
crawlFile();
|
|
1702
|
+
};
|
|
1703
|
+
```
|
|
1704
|
+
|
|
1705
|
+
## convert-to-no-transform-code
|
|
1706
|
+
|
|
1707
|
+
### ❌ Example of incorrect code
|
|
1708
|
+
|
|
1709
|
+
```diff
|
|
1710
|
+
## Rules
|
|
1711
|
+
-- ✅ [remove-illegal-strict-mode](#remove-useless-strict-mode);
|
|
1712
|
+
-- ✅ [add-node-prefix](#add-node-prefix);
|
|
1713
|
+
+- ✅ [add-node-prefix](#add-node-prefix);
|
|
1714
|
+
+- ✅ [remove-illegal-strict-mode](#remove-useless-strict-mode);
|
|
1715
|
+
```
|
|
1716
|
+
|
|
1717
|
+
## convert-traverse-to-include
|
|
1718
|
+
|
|
1719
|
+
### ❌ Example of incorrect code
|
|
1720
|
+
|
|
1721
|
+
```js
|
|
1722
|
+
module.exports.match = () => ({
|
|
1723
|
+
'__a = __b': (vars, path) => {},
|
|
1724
|
+
});
|
|
1725
|
+
module.exports.replace = () => ({
|
|
1726
|
+
'__a = __': '__a',
|
|
1769
1727
|
});
|
|
1770
1728
|
```
|
|
1771
1729
|
|
|
1772
|
-
|
|
1730
|
+
☝️ *There is no `fix` for this rule, it used internally to be more confident about `test coverage`, because of declaration form, transforms cannon be checked by `nyc` and `c8`, and uncovered lines can find unfixable false positives when running on code.
|
|
1731
|
+
This is additional tests, if you forget to test some case (from a big list of rules that is supported) it will be checked with this `rule` and make transforms more stable.*
|
|
1732
|
+
|
|
1733
|
+
## convert-traverse-to-replace
|
|
1773
1734
|
|
|
1774
1735
|
### ❌ Example of incorrect code
|
|
1775
1736
|
|
|
1776
1737
|
```js
|
|
1777
|
-
export const
|
|
1778
|
-
'
|
|
1738
|
+
export const match = () => ({
|
|
1739
|
+
'__a(__args': (vars, path) => {
|
|
1740
|
+
fn(x);
|
|
1741
|
+
return __args[__a];
|
|
1742
|
+
},
|
|
1779
1743
|
});
|
|
1780
1744
|
```
|
|
1781
1745
|
|
|
1782
1746
|
### ✅ Example of correct code
|
|
1783
1747
|
|
|
1784
1748
|
```js
|
|
1785
|
-
export const
|
|
1786
|
-
'
|
|
1749
|
+
export const match = () => ({
|
|
1750
|
+
'__a(__args': ({__args, __a}, path) => {
|
|
1751
|
+
fn(x);
|
|
1752
|
+
return __args[__a];
|
|
1753
|
+
},
|
|
1787
1754
|
});
|
|
1788
1755
|
```
|
|
1789
1756
|
|
|
1790
|
-
##
|
|
1757
|
+
## convert-traverse-to-scan
|
|
1791
1758
|
|
|
1792
|
-
Checkout in
|
|
1759
|
+
Checkout in 🐊**Putout Editor**:
|
|
1760
|
+
|
|
1761
|
+
- [`Traverser`](https://putout.cloudcmd.io/#/gist/afe988c8e53ae70e50bf26512672f3cd/a6677d53b996e85880a4af18250c00e849322bbe);
|
|
1762
|
+
- [`Replacer`](https://putout.cloudcmd.io/#/gist/2e89f498c88f3208beeb85dd01a9178e/ed975281c57f451fc1c3aaf187425a33499af71d);
|
|
1793
1763
|
|
|
1794
1764
|
### ❌ Example of incorrect code
|
|
1795
1765
|
|
|
1796
1766
|
```js
|
|
1797
|
-
|
|
1798
|
-
|
|
1767
|
+
export const match = () => ({
|
|
1768
|
+
'__x __a __expr': ({__x}) => {
|
|
1769
|
+
if (path.isNextPunctuator(assign))
|
|
1770
|
+
return false;
|
|
1771
|
+
|
|
1772
|
+
return isOneOfKeywords(__x, ['const', 'let', 'var']);
|
|
1773
|
+
},
|
|
1799
1774
|
});
|
|
1800
1775
|
```
|
|
1801
1776
|
|
|
1802
1777
|
### ✅ Example of correct code
|
|
1803
1778
|
|
|
1804
1779
|
```js
|
|
1805
|
-
|
|
1806
|
-
|
|
1780
|
+
export const match = () => ({
|
|
1781
|
+
'__x __a __expr': ({__x}) => {
|
|
1782
|
+
if (path.isNextPunctuator(assign))
|
|
1783
|
+
return false;
|
|
1784
|
+
|
|
1785
|
+
return isOneOfKeywords(__x, ['const', 'let', 'var']);
|
|
1786
|
+
},
|
|
1807
1787
|
});
|
|
1808
1788
|
```
|
|
1809
1789
|
|
|
1810
|
-
##
|
|
1790
|
+
## convert-traverse-to-super-traverse
|
|
1811
1791
|
|
|
1812
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/
|
|
1792
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/131b7af8e25a454b293d592d2faa2cd8/f8ae176880de753eb50236d841a1a3bb8e494e2f).
|
|
1813
1793
|
|
|
1814
1794
|
### ❌ Example of incorrect code
|
|
1815
1795
|
|
|
1816
1796
|
```js
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
};
|
|
1797
|
+
compare(a, 'const __a = __b');
|
|
1798
|
+
isIdentifier(a);
|
|
1820
1799
|
```
|
|
1821
1800
|
|
|
1822
1801
|
### ✅ Example of correct code
|
|
1823
1802
|
|
|
1824
1803
|
```js
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
};
|
|
1804
|
+
import {operator, types} from 'putout';
|
|
1805
|
+
|
|
1806
|
+
const {compare} = operator;
|
|
1807
|
+
const {isIdentifier} = types;
|
|
1808
|
+
|
|
1809
|
+
compare(a, 'const __a = __b');
|
|
1810
|
+
isIdentifier(a);
|
|
1828
1811
|
```
|
|
1829
1812
|
|
|
1830
|
-
##
|
|
1813
|
+
## convert-url-to-dirname
|
|
1831
1814
|
|
|
1832
|
-
|
|
1815
|
+
### ❌ Example of incorrect code
|
|
1816
|
+
|
|
1817
|
+
```js
|
|
1818
|
+
test('', ({progress}) => {
|
|
1819
|
+
progress();
|
|
1820
|
+
});
|
|
1821
|
+
```
|
|
1833
1822
|
|
|
1834
|
-
###
|
|
1823
|
+
### ✅ Example of correct code
|
|
1835
1824
|
|
|
1836
1825
|
```js
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
};
|
|
1826
|
+
test('', async ({progress}) => {
|
|
1827
|
+
await progress();
|
|
1828
|
+
});
|
|
1840
1829
|
```
|
|
1841
1830
|
|
|
1842
|
-
|
|
1831
|
+
## create-test
|
|
1843
1832
|
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
};
|
|
1833
|
+
Add properties to `createTest` options, here is example of `.putout.json`:
|
|
1834
|
+
|
|
1835
|
+
```json
|
|
1848
1836
|
```
|
|
1849
1837
|
|
|
1850
|
-
|
|
1838
|
+
Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e2a9f02d352c064ac9a11688feadc923/2a525f0a8a2794c9d26c23914801c512f347abef).
|
|
1851
1839
|
|
|
1852
1840
|
### ❌ Example of incorrect code
|
|
1853
1841
|
|
|
1854
1842
|
```js
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
module.exports = addArgument({
|
|
1859
|
-
t: ['t', 'test("__a", (__args) => __body)'],
|
|
1860
|
-
});
|
|
1843
|
+
module.exports.match = {
|
|
1844
|
+
'let __a = __b': () => false,
|
|
1845
|
+
};
|
|
1861
1846
|
```
|
|
1862
1847
|
|
|
1863
1848
|
### ✅ Example of correct code
|
|
1864
1849
|
|
|
1865
1850
|
```js
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
module.exports = addArgs({
|
|
1870
|
-
t: ['t', 'test("__a", (__args) => __body)'],
|
|
1851
|
+
module.exports.match = () => ({
|
|
1852
|
+
'let __a = __b': () => false,
|
|
1871
1853
|
});
|
|
1872
1854
|
```
|
|
1873
1855
|
|
|
1874
|
-
##
|
|
1856
|
+
## declare
|
|
1875
1857
|
|
|
1876
1858
|
### ❌ Example of incorrect code
|
|
1877
1859
|
|
|
@@ -1898,7 +1880,25 @@ const test = createTest(import.meta.url, {
|
|
|
1898
1880
|
});
|
|
1899
1881
|
```
|
|
1900
1882
|
|
|
1901
|
-
##
|
|
1883
|
+
## declare-path-variable
|
|
1884
|
+
|
|
1885
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/b485bf55785ea836408d0d45c492c3e4/2a0b465076242ebf6a0d8015a90ccf7b0b660a42).
|
|
1886
|
+
|
|
1887
|
+
### ❌ Example of incorrect code
|
|
1888
|
+
|
|
1889
|
+
```js
|
|
1890
|
+
module.exports.report = `'report' should be a 'function'`;
|
|
1891
|
+
```
|
|
1892
|
+
|
|
1893
|
+
### ✅ Example of correct code
|
|
1894
|
+
|
|
1895
|
+
```js
|
|
1896
|
+
module.exports.report = () => `'report' should be a 'function'`;
|
|
1897
|
+
```
|
|
1898
|
+
|
|
1899
|
+
## declare-template-variables
|
|
1900
|
+
|
|
1901
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/71ae86cc372dca8adc79bf53c49e8d5f/c9c8517ee932c18abcfda10c0515253b907ee485).
|
|
1902
1902
|
|
|
1903
1903
|
### ❌ Example of incorrect code
|
|
1904
1904
|
|
|
@@ -1922,20 +1922,6 @@ const test = createTest(import.meta.url, {
|
|
|
1922
1922
|
});
|
|
1923
1923
|
```
|
|
1924
1924
|
|
|
1925
|
-
## convert-report-to-function
|
|
1926
|
-
|
|
1927
|
-
### ❌ Example of incorrect code
|
|
1928
|
-
|
|
1929
|
-
```js
|
|
1930
|
-
module.exports.report = `'report' should be a 'function'`;
|
|
1931
|
-
```
|
|
1932
|
-
|
|
1933
|
-
### ✅ Example of correct code
|
|
1934
|
-
|
|
1935
|
-
```js
|
|
1936
|
-
module.exports.report = () => `'report' should be a 'function'`;
|
|
1937
|
-
```
|
|
1938
|
-
|
|
1939
1925
|
## convert-progress-to-track
|
|
1940
1926
|
|
|
1941
1927
|
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/8736a0cf838a3660b0927e161e4fb06c/9f5c9f810babd4450898069d3d8dc28aceee1e2d).
|
|
@@ -1967,13 +1953,7 @@ module.exports.scan = (root, {push, trackFile}) => {
|
|
|
1967
1953
|
};
|
|
1968
1954
|
```
|
|
1969
1955
|
|
|
1970
|
-
##
|
|
1971
|
-
|
|
1972
|
-
- ✅ import [Nested plugins](https://github.com/coderaiser/putout/tree/master/packages/engine-loader#nested-plugin) in [**Deno** and **Browser**](https://github.com/putoutjs/bundle/);
|
|
1973
|
-
- ✅ easier bundle with rollup without [`dynamicRequireTargets`](https://github.com/rollup/plugins/tree/master/packages/commonjs/#dynamicrequiretargets);
|
|
1974
|
-
- ✅ easier to migrate to **ESM**;
|
|
1975
|
-
|
|
1976
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/38336fcc5b5ae6e441697e098067319c/dd98578c9554b7bd5dceee0499118f7d8216e1da).
|
|
1956
|
+
## includer
|
|
1977
1957
|
|
|
1978
1958
|
### ❌ Example of incorrect code
|
|
1979
1959
|
|
|
@@ -1991,11 +1971,7 @@ module.exports.rules = {
|
|
|
1991
1971
|
};
|
|
1992
1972
|
```
|
|
1993
1973
|
|
|
1994
|
-
##
|
|
1995
|
-
|
|
1996
|
-
To read file content use [`readFileContent`](https://github.com/coderaiser/putout/tree/master/packages/operator-filesystem#readfilecontentfilepath-filepath-string) and never confuse.
|
|
1997
|
-
|
|
1998
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/828da75f16a526652b138948d810ed9e/754bd02869a7e4e119e9fb442dab93df7785fb56).
|
|
1974
|
+
## move-require-on-top-level
|
|
1999
1975
|
|
|
2000
1976
|
### ❌ Example of incorrect code
|
|
2001
1977
|
|
|
@@ -2009,41 +1985,9 @@ const content = getFileContent(file);
|
|
|
2009
1985
|
const content = readFileContent(file);
|
|
2010
1986
|
```
|
|
2011
1987
|
|
|
2012
|
-
##
|
|
2013
|
-
|
|
2014
|
-
### ❌ Example of incorrect code
|
|
2015
|
-
|
|
2016
|
-
```js
|
|
2017
|
-
const test = require('@putout/test')(__dirname, {
|
|
2018
|
-
'remove-debugger': require('..'),
|
|
2019
|
-
});
|
|
2020
|
-
|
|
2021
|
-
test('remove debugger: report', (t) => {
|
|
2022
|
-
t.transform('debugger', {
|
|
2023
|
-
'remove-debugger': require('..'),
|
|
2024
|
-
});
|
|
2025
|
-
t.end();
|
|
2026
|
-
});
|
|
2027
|
-
```
|
|
2028
|
-
|
|
2029
|
-
### ✅ Example of correct code
|
|
2030
|
-
|
|
2031
|
-
```js
|
|
2032
|
-
const removeDebugger = require('..');
|
|
2033
|
-
|
|
2034
|
-
const test = require('@putout/test')(__dirname, {
|
|
2035
|
-
'remove-debugger': removeDebugger,
|
|
2036
|
-
});
|
|
2037
|
-
|
|
2038
|
-
test('remove debugger: report', (t) => {
|
|
2039
|
-
t.transform('debugger', {
|
|
2040
|
-
'remove-debugger': removeDebugger,
|
|
2041
|
-
});
|
|
2042
|
-
t.end();
|
|
2043
|
-
});
|
|
2044
|
-
```
|
|
1988
|
+
## remove-empty-array-from-process
|
|
2045
1989
|
|
|
2046
|
-
|
|
1990
|
+
Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/fc32ff87e91fd28f26a03f55eba0663e/3423926ba0a80d30beafe2ac66c70c517df173e1).
|
|
2047
1991
|
|
|
2048
1992
|
### ❌ Example of incorrect code
|
|
2049
1993
|
|
|
@@ -2052,19 +1996,15 @@ module.exports.include = () => 'cons __a = __b';
|
|
|
2052
1996
|
module.exports.exclude = () => 'var __a = __b';
|
|
2053
1997
|
module.exports.include = 'cons __a = __b';
|
|
2054
1998
|
module.exports.exclude = 'var __a = __b';
|
|
2055
|
-
|
|
2056
1999
|
module.exports.include = [
|
|
2057
2000
|
'cons __a = __b',
|
|
2058
2001
|
];
|
|
2059
|
-
|
|
2060
2002
|
module.exports.exclude = [
|
|
2061
2003
|
'var __a = __b',
|
|
2062
2004
|
];
|
|
2063
|
-
|
|
2064
2005
|
export const include = [
|
|
2065
2006
|
'cons __a = __b',
|
|
2066
2007
|
];
|
|
2067
|
-
|
|
2068
2008
|
export const exclude = [
|
|
2069
2009
|
'var __a = __b',
|
|
2070
2010
|
];
|
|
@@ -2076,24 +2016,20 @@ export const exclude = [
|
|
|
2076
2016
|
module.exports.include = () => [
|
|
2077
2017
|
'const __a = __b',
|
|
2078
2018
|
];
|
|
2079
|
-
|
|
2080
2019
|
module.exports.exclude = () => [
|
|
2081
2020
|
'var __a = __b',
|
|
2082
2021
|
];
|
|
2083
|
-
|
|
2084
2022
|
export const include = () => [
|
|
2085
2023
|
'cons __a = __b',
|
|
2086
2024
|
];
|
|
2087
|
-
|
|
2088
2025
|
export const exclude = () => [
|
|
2089
2026
|
'var __a = __b',
|
|
2090
2027
|
];
|
|
2091
2028
|
```
|
|
2092
2029
|
|
|
2093
|
-
##
|
|
2030
|
+
## remove-empty-object-from-transform
|
|
2094
2031
|
|
|
2095
|
-
|
|
2096
|
-
Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d9c6972ea848ba8e7e745d2479727b65/199c30b986ce7d544397c344ebfc5031c4b53181).
|
|
2032
|
+
Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/f6e8710edf3501a8883f769c82a93048/8060cb8e1505324bb13de511a67d051217a2c39c).
|
|
2097
2033
|
|
|
2098
2034
|
### ❌ Example of incorrect code
|
|
2099
2035
|
|
|
@@ -2123,45 +2059,47 @@ test('plugin-putout: rename-operate-to-operator: no report: operator exist', (t)
|
|
|
2123
2059
|
});
|
|
2124
2060
|
```
|
|
2125
2061
|
|
|
2126
|
-
## remove-
|
|
2062
|
+
## remove-message-from-no-report-after-transform
|
|
2127
2063
|
|
|
2128
|
-
Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/
|
|
2064
|
+
Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/b40b73049530d6c4e142a4d4b09e29e2/2167f30abebc5713e2db916a2a0152e13722e7b1).
|
|
2129
2065
|
|
|
2130
2066
|
### ❌ Example of incorrect code
|
|
2131
2067
|
|
|
2132
2068
|
```js
|
|
2133
|
-
|
|
2069
|
+
test('hello', (t) => {
|
|
2070
|
+
t.transform('nested-labels', {});
|
|
2071
|
+
});
|
|
2134
2072
|
```
|
|
2135
2073
|
|
|
2136
2074
|
### ✅ Example of correct code
|
|
2137
2075
|
|
|
2138
2076
|
```js
|
|
2139
|
-
|
|
2077
|
+
test('hello', (t) => {
|
|
2078
|
+
t.transform('nested-labels');
|
|
2079
|
+
});
|
|
2140
2080
|
```
|
|
2141
2081
|
|
|
2142
|
-
## remove-
|
|
2082
|
+
## remove-unused-get-properties-argument
|
|
2143
2083
|
|
|
2144
|
-
Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/
|
|
2084
|
+
Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/fc32ff87e91fd28f26a03f55eba0663e/3423926ba0a80d30beafe2ac66c70c517df173e1).
|
|
2145
2085
|
|
|
2146
2086
|
### ❌ Example of incorrect code
|
|
2147
2087
|
|
|
2148
2088
|
```js
|
|
2149
|
-
|
|
2150
|
-
t.transform('nested-labels', {});
|
|
2151
|
-
});
|
|
2089
|
+
await process('input', []);
|
|
2152
2090
|
```
|
|
2153
2091
|
|
|
2154
2092
|
### ✅ Example of correct code
|
|
2155
2093
|
|
|
2156
2094
|
```js
|
|
2157
|
-
|
|
2158
|
-
t.transform('nested-labels');
|
|
2159
|
-
});
|
|
2095
|
+
await process('input');
|
|
2160
2096
|
```
|
|
2161
2097
|
|
|
2162
|
-
## remove-
|
|
2098
|
+
## remove-useless-printer-option
|
|
2163
2099
|
|
|
2164
|
-
Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/
|
|
2100
|
+
Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/f176313cf67fd6d7138470385511319f/5b26aa45db21f250016d228b7bbabbb3c10b582b).
|
|
2101
|
+
|
|
2102
|
+
`putout` printer used by default, so there is no need to pass it.
|
|
2165
2103
|
|
|
2166
2104
|
### ❌ Example of incorrect code
|
|
2167
2105
|
|
|
@@ -2188,9 +2126,9 @@ const {
|
|
|
2188
2126
|
} = getProperties(__jsonPath, ['parser', 'rules', 'extends']);
|
|
2189
2127
|
```
|
|
2190
2128
|
|
|
2191
|
-
## remove-
|
|
2129
|
+
## remove-useless-source-argument
|
|
2192
2130
|
|
|
2193
|
-
Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/
|
|
2131
|
+
Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/9b5f94d6a60f3337f925fcc338370d83/7e944de0dfdd64b3c74d490aae21b04015b8262f).
|
|
2194
2132
|
|
|
2195
2133
|
### ❌ Example of incorrect code
|
|
2196
2134
|
|
|
@@ -2210,11 +2148,43 @@ test('github: set-message-of-commit-fixes: no report after transform', (t) => {
|
|
|
2210
2148
|
});
|
|
2211
2149
|
```
|
|
2212
2150
|
|
|
2213
|
-
##
|
|
2151
|
+
## replace-test-message
|
|
2214
2152
|
|
|
2215
|
-
|
|
2153
|
+
Checks that `test message` and used `operator` are synchronized.
|
|
2154
|
+
Check it out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d9c6972ea848ba8e7e745d2479727b65/199c30b986ce7d544397c344ebfc5031c4b53181).
|
|
2216
2155
|
|
|
2217
|
-
|
|
2156
|
+
### ❌ Example of incorrect code
|
|
2157
|
+
|
|
2158
|
+
```js
|
|
2159
|
+
const test = require('@putout/test')(__dirname, {
|
|
2160
|
+
'remove-debugger': require('..'),
|
|
2161
|
+
});
|
|
2162
|
+
|
|
2163
|
+
test('remove debugger: report', (t) => {
|
|
2164
|
+
t.transform('debugger', {
|
|
2165
|
+
'remove-debugger': require('..'),
|
|
2166
|
+
});
|
|
2167
|
+
t.end();
|
|
2168
|
+
});
|
|
2169
|
+
```
|
|
2170
|
+
|
|
2171
|
+
### ✅ Example of correct code
|
|
2172
|
+
|
|
2173
|
+
```js
|
|
2174
|
+
const removeDebugger = require('..');
|
|
2175
|
+
const test = require('@putout/test')(__dirname, {
|
|
2176
|
+
'remove-debugger': removeDebugger,
|
|
2177
|
+
});
|
|
2178
|
+
|
|
2179
|
+
test('remove debugger: report', (t) => {
|
|
2180
|
+
t.transform('debugger', {
|
|
2181
|
+
'remove-debugger': removeDebugger,
|
|
2182
|
+
});
|
|
2183
|
+
t.end();
|
|
2184
|
+
});
|
|
2185
|
+
```
|
|
2186
|
+
|
|
2187
|
+
## shorten-imports
|
|
2218
2188
|
|
|
2219
2189
|
### ❌ Example of incorrect code
|
|
2220
2190
|
|
|
@@ -2237,54 +2207,54 @@ const test = createTest(__dirname, {
|
|
|
2237
2207
|
});
|
|
2238
2208
|
```
|
|
2239
2209
|
|
|
2240
|
-
##
|
|
2210
|
+
## simplify-replace-template
|
|
2241
2211
|
|
|
2242
|
-
|
|
2212
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/a012fc12f4d38038da022f7c8f379fe2/c65bf97c42650aa31c5481849bc934323df892a6).
|
|
2243
2213
|
|
|
2244
2214
|
### ❌ Example of incorrect code
|
|
2245
2215
|
|
|
2246
2216
|
```js
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
findPlaces(ast, source, options);
|
|
2251
|
-
|
|
2252
|
-
tryCatch(transform, ast, source, {});
|
|
2253
|
-
|
|
2254
|
-
tryCatch(findPlaces, ast, source, resultOptions);
|
|
2217
|
+
module.exports.replace = () => ({
|
|
2218
|
+
'if (__a) {__b} else {__c}': () => 'if (__a) __b; else __c',
|
|
2219
|
+
});
|
|
2255
2220
|
```
|
|
2256
2221
|
|
|
2257
2222
|
### ✅ Example of correct code
|
|
2258
2223
|
|
|
2259
2224
|
```js
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
findPlaces(ast, options);
|
|
2264
|
-
|
|
2265
|
-
tryCatch(transform, ast, {});
|
|
2266
|
-
|
|
2267
|
-
tryCatch(findPlaces, ast, resultOptions);
|
|
2225
|
+
module.exports.replace = () => ({
|
|
2226
|
+
'if (__a) {__b} else {__c}': 'if (__a) __b; else __c',
|
|
2227
|
+
});
|
|
2268
2228
|
```
|
|
2269
2229
|
|
|
2270
|
-
##
|
|
2230
|
+
## sort-readme-file
|
|
2271
2231
|
|
|
2272
|
-
Checkout in
|
|
2232
|
+
Checkout in 🐊**Putout Editor**:
|
|
2233
|
+
|
|
2234
|
+
- ✅ [`sort-contents`](https://putout.cloudcmd.io/#/gist/647bcc98ba9eeaa619dfa90d129ee0ec/a19ba868e8c2f97292e763675de65cc1ec98ff66);
|
|
2235
|
+
- ✅ [`sort-headings`](https://putout.cloudcmd.io/#/gist/a5a23310a84cb209e7e5537bab294ab2/0ecd88ffa6e37ac2553cabe5333d307aed2c4a7d);
|
|
2236
|
+
- ✅ [`sort-readme-file`](https://putout.cloudcmd.io/#/gist/ac5f8b64383dabd025f38f177b18b5d2/09751fd2e6659445ed8d8d2102f1d23090a18f49);
|
|
2273
2237
|
|
|
2274
2238
|
### ❌ Example of incorrect code
|
|
2275
2239
|
|
|
2276
2240
|
```js
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2241
|
+
import {tryCatch} from 'try-catch';
|
|
2242
|
+
|
|
2243
|
+
transform(ast, source, options);
|
|
2244
|
+
findPlaces(ast, source, options);
|
|
2245
|
+
tryCatch(transform, ast, source, {});
|
|
2246
|
+
tryCatch(findPlaces, ast, source, resultOptions);
|
|
2280
2247
|
```
|
|
2281
2248
|
|
|
2282
2249
|
### ✅ Example of correct code
|
|
2283
2250
|
|
|
2284
2251
|
```js
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2252
|
+
import {tryCatch} from 'try-catch';
|
|
2253
|
+
|
|
2254
|
+
transform(ast, options);
|
|
2255
|
+
findPlaces(ast, options);
|
|
2256
|
+
tryCatch(transform, ast, {});
|
|
2257
|
+
tryCatch(findPlaces, ast, resultOptions);
|
|
2288
2258
|
```
|
|
2289
2259
|
|
|
2290
2260
|
## apply-fixture-name-to-message"
|