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