@putout/plugin-printer 8.23.0 → 8.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -14,8 +14,8 @@ npm i @putout/plugin-printer -D
|
|
|
14
14
|
## Rules
|
|
15
15
|
|
|
16
16
|
- ✅ [add-args](#add-args);
|
|
17
|
-
- ✅ [add-missing-spaces-to-type-checker](#add-missing-spaces-to-type-checker);
|
|
18
17
|
- ✅ [add-missing-colon-to-type-checker](#add-missing-spaces-to-type-checker);
|
|
18
|
+
- ✅ [add-missing-spaces-to-type-checker](#add-missing-spaces-to-type-checker);
|
|
19
19
|
- ✅ [add-missing-tuples-to-type-checker](#add-missing-tuples-to-type-checker);
|
|
20
20
|
- ✅ [apply-breakline](#apply-breakline);
|
|
21
21
|
- ✅ [apply-computed-print](#apply-computed-print);
|
|
@@ -23,23 +23,24 @@ npm i @putout/plugin-printer -D
|
|
|
23
23
|
- ✅ [apply-linebreak](#apply-linebreak);
|
|
24
24
|
- ✅ [apply-printer-declarations](#apply-printer-declarations);
|
|
25
25
|
- ✅ [apply-types](#apply-types);
|
|
26
|
-
- ✅ [check-type-passed-to-type-checker](#check-type-passed-to-type-checker);
|
|
27
26
|
- ✅ [check-if-success-possible-in-type-checker](#check-if-success-possible-in-type-checker);
|
|
28
|
-
- ✅ [
|
|
27
|
+
- ✅ [check-type-passed-to-type-checker](#check-type-passed-to-type-checker);
|
|
29
28
|
- ✅ [declare](#declare);
|
|
30
29
|
- ✅ [declare-nearby](#declare-nearby);
|
|
30
|
+
- ✅ [merge-tuple-of-type-checker](#merge-tuple-of-type-checker);
|
|
31
31
|
- ✅ [remove-args](#remove-args);
|
|
32
|
-
- ✅ [remove-useless-maybe](#remove-useless-maybe);
|
|
33
|
-
- ✅ [remove-useless-print](#remove-useless-print);
|
|
34
32
|
- ✅ [remove-legacy-test-declaration](#remove-legacy-test-declaration);
|
|
35
33
|
- ✅ [remove-trailing-spaces-from-type-checker](#remove-trailing-spaces-from-type-checker);
|
|
36
|
-
- ✅ [remove-useless-spaces-from-type-checker](#remove-useless-spaces-from-type-checker);
|
|
37
34
|
- ✅ [remove-useless-arrow-from-type-checker](#remove-useless-arrow-from-type-checker);
|
|
38
35
|
- ✅ [remove-useless-colon-from-type-checker](#remove-useless-colon-from-type-checker);
|
|
39
|
-
- ✅ [remove-useless-
|
|
36
|
+
- ✅ [remove-useless-maybe](#remove-useless-maybe);
|
|
40
37
|
- ✅ [remove-useless-not-from-type-checker](#remove-useless-not-from-type-checker);
|
|
41
38
|
- ✅ [remove-useless-path-from-type-checker](#remove-useless-path-from-type-checker);
|
|
39
|
+
- ✅ [remove-useless-print](#remove-useless-print);
|
|
40
|
+
- ✅ [remove-useless-spaces-from-type-checker](#remove-useless-spaces-from-type-checker);
|
|
41
|
+
- ✅ [remove-useless-tuples-from-type-checker](#remove-useless-tuples-from-type-checker);
|
|
42
42
|
- ✅ [reverse-comparison-in-type-checker](#reverse-comparison-in-type-checker);
|
|
43
|
+
- ✅ [apply-boolean-operator-to-type-checker](#apply-boolean-operator-to-type-checker);
|
|
43
44
|
|
|
44
45
|
## Config
|
|
45
46
|
|
|
@@ -47,91 +48,36 @@ npm i @putout/plugin-printer -D
|
|
|
47
48
|
{
|
|
48
49
|
"rules": {
|
|
49
50
|
"printer/add-args": "on",
|
|
50
|
-
"printer/add-missing-tuples-to-type-checker": "on",
|
|
51
51
|
"printer/add-missing-colon-to-type-checker": "on",
|
|
52
52
|
"printer/add-missing-spaces-to-type-checker": "on",
|
|
53
|
+
"printer/add-missing-tuples-to-type-checker": "on",
|
|
53
54
|
"printer/apply-breakline": "on",
|
|
54
|
-
"printer/apply-linebreak": "on",
|
|
55
55
|
"printer/apply-computed-print": "on",
|
|
56
56
|
"printer/apply-create-test-url": "on",
|
|
57
|
+
"printer/apply-linebreak": "on",
|
|
57
58
|
"printer/apply-printer-declarations": "on",
|
|
58
59
|
"printer/apply-types": "on",
|
|
59
|
-
"printer/check-type-passed-to-type-checker": "on",
|
|
60
60
|
"printer/check-if-success-possible-in-type-checker": "on",
|
|
61
|
+
"printer/check-type-passed-to-type-checker": "on",
|
|
61
62
|
"printer/declare": "on",
|
|
62
63
|
"printer/declare-nearby": "on",
|
|
63
64
|
"printer/merge-tuple-of-type-checker": "on",
|
|
64
65
|
"printer/remove-args": "on",
|
|
65
|
-
"printer/remove-useless-maybe": "on",
|
|
66
66
|
"printer/remove-trailing-spaces-from-type-checker": "on",
|
|
67
|
-
"printer/remove-useless-spaces-from-type-checker": "on",
|
|
68
67
|
"printer/remove-useless-arrow-from-type-checker": "on",
|
|
69
68
|
"printer/remove-useless-colon-from-type-checker": "on",
|
|
69
|
+
"printer/remove-useless-maybe": "on",
|
|
70
70
|
"printer/remove-useless-not-from-type-checker": "on",
|
|
71
71
|
"printer/remove-useless-path-from-type-checker": "on",
|
|
72
|
-
"printer/remove-useless-tuples-from-type-checker": "on",
|
|
73
72
|
"printer/remove-useless-print": "on",
|
|
74
|
-
"printer/
|
|
73
|
+
"printer/remove-useless-spaces-from-type-checker": "on",
|
|
74
|
+
"printer/remove-useless-tuples-from-type-checker": "on",
|
|
75
|
+
"printer/reverse-comparison-in-type-checker": "on",
|
|
76
|
+
"printer/apply-boolean-operator-to-type-checker": "on"
|
|
75
77
|
}
|
|
76
78
|
}
|
|
77
79
|
```
|
|
78
80
|
|
|
79
|
-
## apply-breakline
|
|
80
|
-
|
|
81
|
-
```diff
|
|
82
|
-
-print.newline();
|
|
83
|
-
-indent();
|
|
84
|
-
print.breakline();
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
## apply-linebreak;
|
|
88
|
-
|
|
89
|
-
```diff
|
|
90
|
-
-indent();
|
|
91
|
-
-print.newline();
|
|
92
|
-
print.linebreak();
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
## apply-printer-declarations
|
|
96
|
-
|
|
97
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/2fc66c476a235eb25f47e55fd7b33042/b0371fe2dd62e8f9fe5ce1fff6d352386e69fcc6).
|
|
98
|
-
|
|
99
|
-
### ❌ Example of incorrect code
|
|
100
|
-
|
|
101
|
-
```js
|
|
102
|
-
export const ExportNamedDeclaration = (path, printer, {indent}) => {
|
|
103
|
-
const {print, write} = printer;
|
|
104
|
-
const {leadingComments} = path.node;
|
|
105
|
-
|
|
106
|
-
indent();
|
|
107
|
-
};
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
### ✅ Example of correct code
|
|
111
|
-
|
|
112
|
-
```js
|
|
113
|
-
export const ExportNamedDeclaration = (path, printer) => {
|
|
114
|
-
const {leadingComments} = path.node;
|
|
115
|
-
const {
|
|
116
|
-
print,
|
|
117
|
-
write,
|
|
118
|
-
indent,
|
|
119
|
-
} = printer;
|
|
120
|
-
|
|
121
|
-
indent();
|
|
122
|
-
};
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
## apply-types
|
|
126
|
-
|
|
127
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/8a88fec812a52e302cf7b191eca2f49e/474ca87860d2eab755373ba9dc8b12efc4a80252).
|
|
128
|
-
|
|
129
|
-
```diff
|
|
130
|
-
-const {isIdentifier} = require('@babel/types');
|
|
131
|
-
+const {types} = require('@babel/types');
|
|
132
|
-
+const {isIdentifier} = types;
|
|
133
|
-
```
|
|
134
|
-
|
|
135
81
|
## add-args
|
|
136
82
|
|
|
137
83
|
### ❌ Example of incorrect code
|
|
@@ -158,26 +104,12 @@ module.exports = {
|
|
|
158
104
|
};
|
|
159
105
|
```
|
|
160
106
|
|
|
161
|
-
##
|
|
162
|
-
|
|
163
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/2451cd51ebd3dfd20c32b6d22ca176b7/bd593860ff4bb2d66e06cf95bbe103cb1203129d).
|
|
164
|
-
|
|
165
|
-
### ❌ Example of incorrect code
|
|
166
|
-
|
|
167
|
-
```js
|
|
168
|
-
export const beforeIf = createTypeChecker([
|
|
169
|
-
['-:->!', isInsideArray],
|
|
170
|
-
['-:parentPath->', isCoupleLines],
|
|
171
|
-
]);
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
### ✅ Example of correct code
|
|
107
|
+
## apply-linebreak;
|
|
175
108
|
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
]);
|
|
109
|
+
```diff
|
|
110
|
+
-indent();
|
|
111
|
+
-print.newline();
|
|
112
|
+
print.linebreak();
|
|
181
113
|
```
|
|
182
114
|
|
|
183
115
|
## add-missing-colon-to-type-checker
|
|
@@ -202,19 +134,16 @@ export const beforeIf = createTypeChecker([
|
|
|
202
134
|
]);
|
|
203
135
|
```
|
|
204
136
|
|
|
205
|
-
## add-missing-
|
|
137
|
+
## add-missing-spaces-to-type-checker
|
|
206
138
|
|
|
207
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/
|
|
139
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/2451cd51ebd3dfd20c32b6d22ca176b7/bd593860ff4bb2d66e06cf95bbe103cb1203129d).
|
|
208
140
|
|
|
209
141
|
### ❌ Example of incorrect code
|
|
210
142
|
|
|
211
143
|
```js
|
|
212
144
|
export const beforeIf = createTypeChecker([
|
|
213
|
-
'
|
|
214
|
-
'
|
|
215
|
-
'- : -> WrongType',
|
|
216
|
-
['- : ->', isBlockStatement],
|
|
217
|
-
['-', isBlockStatement],
|
|
145
|
+
['-:->!', isInsideArray],
|
|
146
|
+
['-:parentPath->', isCoupleLines],
|
|
218
147
|
]);
|
|
219
148
|
```
|
|
220
149
|
|
|
@@ -222,14 +151,19 @@ export const beforeIf = createTypeChecker([
|
|
|
222
151
|
|
|
223
152
|
```js
|
|
224
153
|
export const beforeIf = createTypeChecker([
|
|
225
|
-
['
|
|
226
|
-
['
|
|
227
|
-
['- : -> WrongType'],
|
|
228
|
-
['- : ->', isBlockStatement],
|
|
229
|
-
['-', isBlockStatement],
|
|
154
|
+
['-: -> !', isInsideArray],
|
|
155
|
+
['-: parentPath ->', isCoupleLines],
|
|
230
156
|
]);
|
|
231
157
|
```
|
|
232
158
|
|
|
159
|
+
## apply-breakline
|
|
160
|
+
|
|
161
|
+
```diff
|
|
162
|
+
-print.newline();
|
|
163
|
+
-indent();
|
|
164
|
+
print.breakline();
|
|
165
|
+
```
|
|
166
|
+
|
|
233
167
|
## apply-computed-print
|
|
234
168
|
|
|
235
169
|
### ❌ Example of incorrect code
|
|
@@ -264,135 +198,19 @@ import {createTest} from '#test';
|
|
|
264
198
|
const {test, fixture} = createTest(import.meta.url);
|
|
265
199
|
```
|
|
266
200
|
|
|
267
|
-
##
|
|
268
|
-
|
|
269
|
-
### ❌ Example of incorrect code
|
|
270
|
-
|
|
271
|
-
```js
|
|
272
|
-
print.indent(is);
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
### ✅ Example of correct code
|
|
276
|
-
|
|
277
|
-
```js
|
|
278
|
-
print.indent();
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
## remove-useless-maybe
|
|
282
|
-
|
|
283
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d448a928400ff37043ae03510ce7c85c/db1a758809e8759f591533f9ef92bef1188d32b0).
|
|
284
|
-
|
|
285
|
-
### ❌ Example of incorrect code
|
|
286
|
-
|
|
287
|
-
```js
|
|
288
|
-
maybe.print.linebreak(wasNewline);
|
|
289
|
-
maybe.print.newline(!wasNewline);
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
### ✅ Example of correct code
|
|
293
|
-
|
|
294
|
-
```js
|
|
295
|
-
maybe.indent(wasNewline);
|
|
296
|
-
print.newline();
|
|
297
|
-
```
|
|
298
|
-
|
|
299
|
-
## remove-useless-spaces-from-type-checker
|
|
300
|
-
|
|
301
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/2e90aa74898a496b488f9c369801b47a/fbd700d965952e80588ec61054b3ed7aee4d17a2).
|
|
302
|
-
|
|
303
|
-
### ❌ Example of incorrect code
|
|
304
|
-
|
|
305
|
-
```js
|
|
306
|
-
export const beforeIf = createTypeChecker([
|
|
307
|
-
['- : -> !', isInsideArray],
|
|
308
|
-
]);
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
### ✅ Example of correct code
|
|
312
|
-
|
|
313
|
-
```js
|
|
314
|
-
export const beforeIf = createTypeChecker([
|
|
315
|
-
['-: -> !', isInsideArray],
|
|
316
|
-
]);
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
## remove-useless-arrow-from-type-checker
|
|
320
|
-
|
|
321
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/c12c37b793192eadb60fac332d95cc3b/3f4aa557c65897f4967712f30e51c29483feddc8).
|
|
322
|
-
|
|
323
|
-
### ❌ Example of incorrect code
|
|
324
|
-
|
|
325
|
-
```js
|
|
326
|
-
const isTwoLongStringsInsideArray = createTypeChecker([
|
|
327
|
-
['-: -> !', isTwoLongStrings],
|
|
328
|
-
['+: parentPath -> -> ArrayExpression'],
|
|
329
|
-
]);
|
|
330
|
-
```
|
|
331
|
-
|
|
332
|
-
### ✅ Example of correct code
|
|
333
|
-
|
|
334
|
-
```js
|
|
335
|
-
const isTwoLongStringsInsideArray = createTypeChecker([
|
|
336
|
-
['-: -> !', isTwoLongStrings],
|
|
337
|
-
['+: parentPath -> ArrayExpression'],
|
|
338
|
-
]);
|
|
339
|
-
```
|
|
340
|
-
|
|
341
|
-
## remove-useless-colon-from-type-checker
|
|
342
|
-
|
|
343
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/49a35399bd43d56bfd0221b3a0ace3b0/3ff3bdc8cb5f2a06786e9b616252d1b5f506dd73).
|
|
344
|
-
|
|
345
|
-
### ❌ Example of incorrect code
|
|
346
|
-
|
|
347
|
-
```js
|
|
348
|
-
export const beforeIf = createTypeChecker([
|
|
349
|
-
['+:', isInsideArray],
|
|
350
|
-
['-:', isCoupleLines],
|
|
351
|
-
]);
|
|
352
|
-
```
|
|
353
|
-
|
|
354
|
-
### ✅ Example of correct code
|
|
355
|
-
|
|
356
|
-
```js
|
|
357
|
-
export const beforeIf = createTypeChecker([
|
|
358
|
-
['+', isInsideArray],
|
|
359
|
-
['-', isCoupleLines],
|
|
360
|
-
]);
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
## remove-useless-not-from-type-checker
|
|
364
|
-
|
|
365
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/051b981021fd1e048b675106f0850211/2022b9797125016d4e5c5e6b5d4e066ab2e103ad).
|
|
366
|
-
|
|
367
|
-
### ❌ Example of incorrect code
|
|
368
|
-
|
|
369
|
-
```js
|
|
370
|
-
export const beforeIf = createTypeChecker([
|
|
371
|
-
['-: -> !+'],
|
|
372
|
-
['+: -> !-'],
|
|
373
|
-
]);
|
|
374
|
-
```
|
|
375
|
-
|
|
376
|
-
### ✅ Example of correct code
|
|
377
|
-
|
|
378
|
-
```js
|
|
379
|
-
export const beforeIf = createTypeChecker([
|
|
380
|
-
['-: -> -'],
|
|
381
|
-
['+: -> +'],
|
|
382
|
-
]);
|
|
383
|
-
```
|
|
384
|
-
|
|
385
|
-
## remove-useless-path-from-type-checker
|
|
386
|
-
|
|
387
|
-
Selector always starts from `path`, so it can be `parentPath.`, or `node.`, but never `path.`, since it is self reference.
|
|
201
|
+
## add-missing-tuple-to-type-checker
|
|
388
202
|
|
|
389
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/
|
|
203
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/9fdfda423df3af9b0f08541710706299/0259bba117997861fe7573bad5477282f4df8554).
|
|
390
204
|
|
|
391
205
|
### ❌ Example of incorrect code
|
|
392
206
|
|
|
393
207
|
```js
|
|
394
208
|
export const beforeIf = createTypeChecker([
|
|
395
|
-
|
|
209
|
+
'- : -> !StringLiteral',
|
|
210
|
+
'- : -> BlockStatement',
|
|
211
|
+
'- : -> WrongType',
|
|
212
|
+
['- : ->', isBlockStatement],
|
|
213
|
+
['-', isBlockStatement],
|
|
396
214
|
]);
|
|
397
215
|
```
|
|
398
216
|
|
|
@@ -400,50 +218,52 @@ export const beforeIf = createTypeChecker([
|
|
|
400
218
|
|
|
401
219
|
```js
|
|
402
220
|
export const beforeIf = createTypeChecker([
|
|
403
|
-
['
|
|
404
|
-
]);
|
|
405
|
-
```
|
|
406
|
-
|
|
407
|
-
## remove-useless-tuples-from-type-checker
|
|
408
|
-
|
|
409
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/f53f386b607115e0a96f7e294e34761e/cefd72aba4fcade59bbf8faa59739bac5c2fe057).
|
|
410
|
-
|
|
411
|
-
### ❌ Example of incorrect code
|
|
412
|
-
|
|
413
|
-
```js
|
|
414
|
-
export const allStrings = createTypeChecker([
|
|
221
|
+
['- : -> !StringLiteral'],
|
|
415
222
|
['- : -> BlockStatement'],
|
|
416
223
|
['- : -> WrongType'],
|
|
224
|
+
['- : ->', isBlockStatement],
|
|
225
|
+
['-', isBlockStatement],
|
|
417
226
|
]);
|
|
418
227
|
```
|
|
419
228
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
```js
|
|
423
|
-
export const allStrings = createTypeChecker([
|
|
424
|
-
'- : -> BlockStatement',
|
|
425
|
-
'- : -> WrongType',
|
|
426
|
-
]);
|
|
427
|
-
```
|
|
428
|
-
|
|
429
|
-
## remove-trailing-spaces-from-type-checker
|
|
229
|
+
## apply-printer-declarations
|
|
430
230
|
|
|
431
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/
|
|
231
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/2fc66c476a235eb25f47e55fd7b33042/b0371fe2dd62e8f9fe5ce1fff6d352386e69fcc6).
|
|
432
232
|
|
|
433
233
|
### ❌ Example of incorrect code
|
|
434
234
|
|
|
435
235
|
```js
|
|
436
|
-
export const
|
|
437
|
-
|
|
438
|
-
|
|
236
|
+
export const ExportNamedDeclaration = (path, printer, {indent}) => {
|
|
237
|
+
const {print, write} = printer;
|
|
238
|
+
const {leadingComments} = path.node;
|
|
239
|
+
|
|
240
|
+
indent();
|
|
241
|
+
};
|
|
439
242
|
```
|
|
440
243
|
|
|
441
244
|
### ✅ Example of correct code
|
|
442
245
|
|
|
443
246
|
```js
|
|
444
|
-
export const
|
|
445
|
-
|
|
446
|
-
|
|
247
|
+
export const ExportNamedDeclaration = (path, printer) => {
|
|
248
|
+
const {leadingComments} = path.node;
|
|
249
|
+
const {
|
|
250
|
+
print,
|
|
251
|
+
write,
|
|
252
|
+
indent,
|
|
253
|
+
} = printer;
|
|
254
|
+
|
|
255
|
+
indent();
|
|
256
|
+
};
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## apply-types
|
|
260
|
+
|
|
261
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/8a88fec812a52e302cf7b191eca2f49e/474ca87860d2eab755373ba9dc8b12efc4a80252).
|
|
262
|
+
|
|
263
|
+
```diff
|
|
264
|
+
-const {isIdentifier} = require('@babel/types');
|
|
265
|
+
+const {types} = require('@babel/types');
|
|
266
|
+
+const {isIdentifier} = types;
|
|
447
267
|
```
|
|
448
268
|
|
|
449
269
|
## check-if-success-possible-in-type-checker
|
|
@@ -597,6 +417,201 @@ export const isNewlineAfterComma = createTypeChecker([
|
|
|
597
417
|
]);
|
|
598
418
|
```
|
|
599
419
|
|
|
420
|
+
## remove-args
|
|
421
|
+
|
|
422
|
+
### ❌ Example of incorrect code
|
|
423
|
+
|
|
424
|
+
```js
|
|
425
|
+
print.indent(is);
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
### ✅ Example of correct code
|
|
429
|
+
|
|
430
|
+
```js
|
|
431
|
+
print.indent();
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
## remove-legacy-test-declaration
|
|
435
|
+
|
|
436
|
+
```diff
|
|
437
|
+
-const {printExtension} = require('../../../test/printer');
|
|
438
|
+
-const {readFixtures} = require('../../../test/fixture');
|
|
439
|
+
-
|
|
440
|
+
-const fixture = readFixtures(__dirname);
|
|
441
|
+
-
|
|
442
|
+
-const test = extend({
|
|
443
|
+
- print: printExtension,
|
|
444
|
+
-});
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
## remove-trailing-spaces-from-type-checker
|
|
448
|
+
|
|
449
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/91d33e39485c31e76b534ad8447ba4db/abca8d21ad6edc1f6fed23edb05fa166677f11d6).
|
|
450
|
+
|
|
451
|
+
### ❌ Example of incorrect code
|
|
452
|
+
|
|
453
|
+
```js
|
|
454
|
+
export const beforeIf = createTypeChecker([
|
|
455
|
+
['-: parentPath -> ', isCoupleLines],
|
|
456
|
+
]);
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
### ✅ Example of correct code
|
|
460
|
+
|
|
461
|
+
```js
|
|
462
|
+
export const beforeIf = createTypeChecker([
|
|
463
|
+
['-: parentPath ->', isCoupleLines],
|
|
464
|
+
]);
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
## remove-useless-arrow-from-type-checker
|
|
468
|
+
|
|
469
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/c12c37b793192eadb60fac332d95cc3b/3f4aa557c65897f4967712f30e51c29483feddc8).
|
|
470
|
+
|
|
471
|
+
### ❌ Example of incorrect code
|
|
472
|
+
|
|
473
|
+
```js
|
|
474
|
+
const isTwoLongStringsInsideArray = createTypeChecker([
|
|
475
|
+
['-: -> !', isTwoLongStrings],
|
|
476
|
+
['+: parentPath -> -> ArrayExpression'],
|
|
477
|
+
]);
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
### ✅ Example of correct code
|
|
481
|
+
|
|
482
|
+
```js
|
|
483
|
+
const isTwoLongStringsInsideArray = createTypeChecker([
|
|
484
|
+
['-: -> !', isTwoLongStrings],
|
|
485
|
+
['+: parentPath -> ArrayExpression'],
|
|
486
|
+
]);
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
## remove-useless-colon-from-type-checker
|
|
490
|
+
|
|
491
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/49a35399bd43d56bfd0221b3a0ace3b0/3ff3bdc8cb5f2a06786e9b616252d1b5f506dd73).
|
|
492
|
+
|
|
493
|
+
### ❌ Example of incorrect code
|
|
494
|
+
|
|
495
|
+
```js
|
|
496
|
+
export const beforeIf = createTypeChecker([
|
|
497
|
+
['+:', isInsideArray],
|
|
498
|
+
['-:', isCoupleLines],
|
|
499
|
+
]);
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
### ✅ Example of correct code
|
|
503
|
+
|
|
504
|
+
```js
|
|
505
|
+
export const beforeIf = createTypeChecker([
|
|
506
|
+
['+', isInsideArray],
|
|
507
|
+
['-', isCoupleLines],
|
|
508
|
+
]);
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
## remove-useless-maybe
|
|
512
|
+
|
|
513
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d448a928400ff37043ae03510ce7c85c/db1a758809e8759f591533f9ef92bef1188d32b0).
|
|
514
|
+
|
|
515
|
+
### ❌ Example of incorrect code
|
|
516
|
+
|
|
517
|
+
```js
|
|
518
|
+
maybe.print.linebreak(wasNewline);
|
|
519
|
+
maybe.print.newline(!wasNewline);
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
### ✅ Example of correct code
|
|
523
|
+
|
|
524
|
+
```js
|
|
525
|
+
maybe.indent(wasNewline);
|
|
526
|
+
print.newline();
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
## remove-useless-not-from-type-checker
|
|
530
|
+
|
|
531
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/051b981021fd1e048b675106f0850211/2022b9797125016d4e5c5e6b5d4e066ab2e103ad).
|
|
532
|
+
|
|
533
|
+
### ❌ Example of incorrect code
|
|
534
|
+
|
|
535
|
+
```js
|
|
536
|
+
export const beforeIf = createTypeChecker([
|
|
537
|
+
['-: -> !+'],
|
|
538
|
+
['+: -> !-'],
|
|
539
|
+
]);
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
### ✅ Example of correct code
|
|
543
|
+
|
|
544
|
+
```js
|
|
545
|
+
export const beforeIf = createTypeChecker([
|
|
546
|
+
['-: -> -'],
|
|
547
|
+
['+: -> +'],
|
|
548
|
+
]);
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
## remove-useless-path-from-type-checker
|
|
552
|
+
|
|
553
|
+
Selector always starts from `path`, so it can be `parentPath.`, or `node.`, but never `path.`, since it is self reference.
|
|
554
|
+
|
|
555
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/ef8e1dc1036a4a2fcc99b32c3dc661e2/bc43a082dc9cb5ed8a8afe6964174f0d1be2e1c1).
|
|
556
|
+
|
|
557
|
+
### ❌ Example of incorrect code
|
|
558
|
+
|
|
559
|
+
```js
|
|
560
|
+
export const beforeIf = createTypeChecker([
|
|
561
|
+
['-: path.parentPath -> ', isCoupleLines],
|
|
562
|
+
]);
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
### ✅ Example of correct code
|
|
566
|
+
|
|
567
|
+
```js
|
|
568
|
+
export const beforeIf = createTypeChecker([
|
|
569
|
+
['-: parentPath -> ', isCoupleLines],
|
|
570
|
+
]);
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
## remove-useless-spaces-from-type-checker
|
|
574
|
+
|
|
575
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/2e90aa74898a496b488f9c369801b47a/fbd700d965952e80588ec61054b3ed7aee4d17a2).
|
|
576
|
+
|
|
577
|
+
### ❌ Example of incorrect code
|
|
578
|
+
|
|
579
|
+
```js
|
|
580
|
+
export const beforeIf = createTypeChecker([
|
|
581
|
+
['- : -> !', isInsideArray],
|
|
582
|
+
]);
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
### ✅ Example of correct code
|
|
586
|
+
|
|
587
|
+
```js
|
|
588
|
+
export const beforeIf = createTypeChecker([
|
|
589
|
+
['-: -> !', isInsideArray],
|
|
590
|
+
]);
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
## remove-useless-tuples-from-type-checker
|
|
594
|
+
|
|
595
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/f53f386b607115e0a96f7e294e34761e/cefd72aba4fcade59bbf8faa59739bac5c2fe057).
|
|
596
|
+
|
|
597
|
+
### ❌ Example of incorrect code
|
|
598
|
+
|
|
599
|
+
```js
|
|
600
|
+
export const allStrings = createTypeChecker([
|
|
601
|
+
['- : -> BlockStatement'],
|
|
602
|
+
['- : -> WrongType'],
|
|
603
|
+
]);
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
### ✅ Example of correct code
|
|
607
|
+
|
|
608
|
+
```js
|
|
609
|
+
export const allStrings = createTypeChecker([
|
|
610
|
+
'- : -> BlockStatement',
|
|
611
|
+
'- : -> WrongType',
|
|
612
|
+
]);
|
|
613
|
+
```
|
|
614
|
+
|
|
600
615
|
## reverse-comparison-in-type-checker
|
|
601
616
|
|
|
602
617
|
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/ae2335d32022de240e918ce077144767/f25c5a11f746fe532f81adede991286cb77d1b11).
|
|
@@ -623,19 +638,6 @@ const isMoreThenMaxElementLengthInOneLine = createTypeChecker([
|
|
|
623
638
|
]);
|
|
624
639
|
```
|
|
625
640
|
|
|
626
|
-
## remove-legacy-test-declaration
|
|
627
|
-
|
|
628
|
-
```diff
|
|
629
|
-
-const {printExtension} = require('../../../test/printer');
|
|
630
|
-
-const {readFixtures} = require('../../../test/fixture');
|
|
631
|
-
-
|
|
632
|
-
-const fixture = readFixtures(__dirname);
|
|
633
|
-
-
|
|
634
|
-
-const test = extend({
|
|
635
|
-
- print: printExtension,
|
|
636
|
-
-});
|
|
637
|
-
```
|
|
638
|
-
|
|
639
641
|
## reverse-comparison-in-type-checker
|
|
640
642
|
|
|
641
643
|
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/be2bb33f5c7ac7b687c1fa856704bc73/e57fa5a3ded571adca03f5bdeb5a0f63a594aa81).
|
|
@@ -662,6 +664,30 @@ export const ExpressionStatement = (path, {indent, print}) => {
|
|
|
662
664
|
};
|
|
663
665
|
```
|
|
664
666
|
|
|
667
|
+
## apply-boolean-operator-to-type-checker
|
|
668
|
+
|
|
669
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/053946bd010f04ad87e148c648d3af32/a69e0182048d692747b34df94ac4ce0b47d49f33).
|
|
670
|
+
|
|
671
|
+
### ❌ Example of incorrect code
|
|
672
|
+
|
|
673
|
+
```js
|
|
674
|
+
const isNotMarked = createTypeChecker([
|
|
675
|
+
['-: node.async', not(Boolean)],
|
|
676
|
+
['-: __putout_promises_add_missing_async', Boolean],
|
|
677
|
+
['+', Boolean],
|
|
678
|
+
]);
|
|
679
|
+
```
|
|
680
|
+
|
|
681
|
+
### ✅ Example of correct code
|
|
682
|
+
|
|
683
|
+
```js
|
|
684
|
+
const isNotMarked = createTypeChecker([
|
|
685
|
+
['-: node.async -> -'],
|
|
686
|
+
['-: __putout_promises_add_missing_async -> +'],
|
|
687
|
+
['+ -> +'],
|
|
688
|
+
]);
|
|
689
|
+
```
|
|
690
|
+
|
|
665
691
|
## License
|
|
666
692
|
|
|
667
693
|
MIT
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {operator, types} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
compare,
|
|
5
|
+
setLiteralValue,
|
|
6
|
+
} = operator;
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
isArrayExpression,
|
|
10
|
+
isIdentifier,
|
|
11
|
+
isCallExpression,
|
|
12
|
+
} = types;
|
|
13
|
+
|
|
14
|
+
export const report = ({operator}) => `Apply boolean operator: '${operator}'`;
|
|
15
|
+
|
|
16
|
+
export const fix = ({path, operator}) => {
|
|
17
|
+
const [first] = path.node.elements;
|
|
18
|
+
const {value} = first;
|
|
19
|
+
|
|
20
|
+
setLiteralValue(first, `${value} -> ${operator}`);
|
|
21
|
+
path.node.elements.pop();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const traverse = ({push}) => ({
|
|
25
|
+
ArrayExpression(path) {
|
|
26
|
+
const {parentPath} = path;
|
|
27
|
+
|
|
28
|
+
if (!isCallExpression(parentPath))
|
|
29
|
+
return;
|
|
30
|
+
|
|
31
|
+
const {callee} = parentPath.node;
|
|
32
|
+
|
|
33
|
+
if (!isIdentifier(callee, {name: 'createTypeChecker'}))
|
|
34
|
+
return;
|
|
35
|
+
|
|
36
|
+
const elements = path.get('elements');
|
|
37
|
+
|
|
38
|
+
for (const element of elements) {
|
|
39
|
+
if (!isArrayExpression(element))
|
|
40
|
+
continue;
|
|
41
|
+
|
|
42
|
+
const [, checker] = element.get('elements');
|
|
43
|
+
|
|
44
|
+
if (!checker)
|
|
45
|
+
return;
|
|
46
|
+
|
|
47
|
+
if (isIdentifier(checker.node, {name: 'Boolean'}))
|
|
48
|
+
push({
|
|
49
|
+
operator: '+',
|
|
50
|
+
path: element,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
if (compare(checker.node, 'not(Boolean)'))
|
|
54
|
+
push({
|
|
55
|
+
operator: '-',
|
|
56
|
+
path: element,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
});
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as applyBooleanOperatorToTypeChecker from './apply-boolean-operator-to-type-checker/index.js';
|
|
1
2
|
import * as declareNearby from './declare-nearby/index.js';
|
|
2
3
|
import * as applyPrinterDeclarations from './apply-printer-declarations/index.js';
|
|
3
4
|
import * as removeUselessPrint from './remove-useless-print/index.js';
|
|
@@ -56,4 +57,5 @@ export const rules = {
|
|
|
56
57
|
'add-missing-arrow-to-type-checker': addMissingArrowToTypeChecker,
|
|
57
58
|
'remove-useless-print': removeUselessPrint,
|
|
58
59
|
'declare-nearby': declareNearby,
|
|
60
|
+
'apply-boolean-operator-to-type-checker': applyBooleanOperatorToTypeChecker,
|
|
59
61
|
};
|
|
@@ -42,11 +42,12 @@ export const traverse = ({push}) => ({
|
|
|
42
42
|
function createWhere(path) {
|
|
43
43
|
const {value} = path.node;
|
|
44
44
|
const where = [];
|
|
45
|
+
const hasNot = value.includes('!');
|
|
45
46
|
|
|
46
47
|
if (value.includes('-> ->'))
|
|
47
48
|
where.push('duplicate');
|
|
48
49
|
|
|
49
|
-
if (isInsideCompareTuple(path) && value.includes(' -> '))
|
|
50
|
+
if (!hasNot && isInsideCompareTuple(path) && value.includes(' -> '))
|
|
50
51
|
where.push('useless');
|
|
51
52
|
|
|
52
53
|
return where;
|
|
@@ -63,7 +64,7 @@ function removeArrow(value, where) {
|
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
function isInsideCompareTuple({parentPath}) {
|
|
66
|
-
if (!isArrayExpression(parentPath))
|
|
67
|
+
if (!isArrayExpression(parentPath.parentPath))
|
|
67
68
|
return false;
|
|
68
69
|
|
|
69
70
|
return parentPath.node.elements.length === 3;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-printer",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.24.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout plugin adds support of transformations for @putout/printer",
|