@putout/plugin-printer 8.24.0 β 9.0.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 +11 -426
- package/lib/apply-computed-print/index.js +11 -0
- package/lib/index.js +0 -32
- package/package.json +1 -1
- package/lib/add-missing-arrow-to-type-checker/index.js +0 -77
- package/lib/add-missing-colon-to-type-checker/index.js +0 -65
- package/lib/add-missing-spaces-to-type-checker/index.js +0 -93
- package/lib/add-missing-tuples-to-type-checker/index.js +0 -94
- package/lib/apply-boolean-operator-to-type-checker/index.js +0 -60
- package/lib/check-if-success-possible-in-type-checker/index.js +0 -51
- package/lib/check-type-passed-to-type-checker/index.js +0 -97
- package/lib/merge-tuples-of-type-checkers/index.js +0 -96
- package/lib/remove-trailing-spaces-from-type-checker/index.js +0 -35
- package/lib/remove-useless-arrow-from-type-checker/index.js +0 -71
- package/lib/remove-useless-colon-from-type-checker/index.js +0 -65
- package/lib/remove-useless-not-from-type-checker/index.js +0 -79
- package/lib/remove-useless-path-from-type-checker/index.js +0 -70
- package/lib/remove-useless-spaces-from-type-checker/index.js +0 -78
- package/lib/remove-useless-tuples-from-type-checker/index.js +0 -67
- package/lib/reverse-comparison-in-type-checker/index.js +0 -32
- package/lib/types.js +0 -22
package/README.md
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
π[**Putout**](https://github.com/coderaiser/putout) adds support of transformations for [`@putout/printer`](https://github.com/putoutjs/printer).
|
|
7
7
|
|
|
8
|
+
> Type-checker rules moved to [`@putout/plugin-type-checker`](https://github.com/coderaiser/putout/tree/master/packages/plugin-type-checker#readme).
|
|
9
|
+
|
|
8
10
|
## Install
|
|
9
11
|
|
|
10
12
|
```
|
|
@@ -14,33 +16,18 @@ npm i @putout/plugin-printer -D
|
|
|
14
16
|
## Rules
|
|
15
17
|
|
|
16
18
|
- β
[add-args](#add-args);
|
|
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
|
-
- β
[add-missing-tuples-to-type-checker](#add-missing-tuples-to-type-checker);
|
|
20
19
|
- β
[apply-breakline](#apply-breakline);
|
|
21
20
|
- β
[apply-computed-print](#apply-computed-print);
|
|
22
21
|
- β
[apply-create-test-url](#apply-create-test-url);
|
|
23
22
|
- β
[apply-linebreak](#apply-linebreak);
|
|
24
23
|
- β
[apply-printer-declarations](#apply-printer-declarations);
|
|
25
24
|
- β
[apply-types](#apply-types);
|
|
26
|
-
- β
[check-if-success-possible-in-type-checker](#check-if-success-possible-in-type-checker);
|
|
27
|
-
- β
[check-type-passed-to-type-checker](#check-type-passed-to-type-checker);
|
|
28
25
|
- β
[declare](#declare);
|
|
29
26
|
- β
[declare-nearby](#declare-nearby);
|
|
30
|
-
- β
[merge-tuple-of-type-checker](#merge-tuple-of-type-checker);
|
|
31
27
|
- β
[remove-args](#remove-args);
|
|
32
28
|
- β
[remove-legacy-test-declaration](#remove-legacy-test-declaration);
|
|
33
|
-
- β
[remove-trailing-spaces-from-type-checker](#remove-trailing-spaces-from-type-checker);
|
|
34
|
-
- β
[remove-useless-arrow-from-type-checker](#remove-useless-arrow-from-type-checker);
|
|
35
|
-
- β
[remove-useless-colon-from-type-checker](#remove-useless-colon-from-type-checker);
|
|
36
29
|
- β
[remove-useless-maybe](#remove-useless-maybe);
|
|
37
|
-
- β
[remove-useless-not-from-type-checker](#remove-useless-not-from-type-checker);
|
|
38
|
-
- β
[remove-useless-path-from-type-checker](#remove-useless-path-from-type-checker);
|
|
39
30
|
- β
[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
|
-
- β
[reverse-comparison-in-type-checker](#reverse-comparison-in-type-checker);
|
|
43
|
-
- β
[apply-boolean-operator-to-type-checker](#apply-boolean-operator-to-type-checker);
|
|
44
31
|
|
|
45
32
|
## Config
|
|
46
33
|
|
|
@@ -48,32 +35,17 @@ npm i @putout/plugin-printer -D
|
|
|
48
35
|
{
|
|
49
36
|
"rules": {
|
|
50
37
|
"printer/add-args": "on",
|
|
51
|
-
"printer/add-missing-colon-to-type-checker": "on",
|
|
52
|
-
"printer/add-missing-spaces-to-type-checker": "on",
|
|
53
|
-
"printer/add-missing-tuples-to-type-checker": "on",
|
|
54
38
|
"printer/apply-breakline": "on",
|
|
55
39
|
"printer/apply-computed-print": "on",
|
|
56
40
|
"printer/apply-create-test-url": "on",
|
|
57
41
|
"printer/apply-linebreak": "on",
|
|
58
42
|
"printer/apply-printer-declarations": "on",
|
|
59
43
|
"printer/apply-types": "on",
|
|
60
|
-
"printer/check-if-success-possible-in-type-checker": "on",
|
|
61
|
-
"printer/check-type-passed-to-type-checker": "on",
|
|
62
44
|
"printer/declare": "on",
|
|
63
45
|
"printer/declare-nearby": "on",
|
|
64
|
-
"printer/merge-tuple-of-type-checker": "on",
|
|
65
46
|
"printer/remove-args": "on",
|
|
66
|
-
"printer/remove-trailing-spaces-from-type-checker": "on",
|
|
67
|
-
"printer/remove-useless-arrow-from-type-checker": "on",
|
|
68
|
-
"printer/remove-useless-colon-from-type-checker": "on",
|
|
69
47
|
"printer/remove-useless-maybe": "on",
|
|
70
|
-
"printer/remove-useless-
|
|
71
|
-
"printer/remove-useless-path-from-type-checker": "on",
|
|
72
|
-
"printer/remove-useless-print": "on",
|
|
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"
|
|
48
|
+
"printer/remove-useless-print": "on"
|
|
77
49
|
}
|
|
78
50
|
}
|
|
79
51
|
```
|
|
@@ -112,50 +84,6 @@ module.exports = {
|
|
|
112
84
|
print.linebreak();
|
|
113
85
|
```
|
|
114
86
|
|
|
115
|
-
## add-missing-colon-to-type-checker
|
|
116
|
-
|
|
117
|
-
Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/97d38d9bee0586deb8c627c19e399a27/889646df2dcfcfe86f7eb0efb6e3ed5791701f58).
|
|
118
|
-
|
|
119
|
-
### β Example of incorrect code
|
|
120
|
-
|
|
121
|
-
```js
|
|
122
|
-
export const beforeIf = createTypeChecker([
|
|
123
|
-
['+ -> !', isInsideArray],
|
|
124
|
-
['- parentPath ->', isCoupleLines],
|
|
125
|
-
]);
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
### β
Example of correct code
|
|
129
|
-
|
|
130
|
-
```js
|
|
131
|
-
export const beforeIf = createTypeChecker([
|
|
132
|
-
['+: -> !', isInsideArray],
|
|
133
|
-
['-: parentPath ->', isCoupleLines],
|
|
134
|
-
]);
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
## add-missing-spaces-to-type-checker
|
|
138
|
-
|
|
139
|
-
Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/2451cd51ebd3dfd20c32b6d22ca176b7/bd593860ff4bb2d66e06cf95bbe103cb1203129d).
|
|
140
|
-
|
|
141
|
-
### β Example of incorrect code
|
|
142
|
-
|
|
143
|
-
```js
|
|
144
|
-
export const beforeIf = createTypeChecker([
|
|
145
|
-
['-:->!', isInsideArray],
|
|
146
|
-
['-:parentPath->', isCoupleLines],
|
|
147
|
-
]);
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
### β
Example of correct code
|
|
151
|
-
|
|
152
|
-
```js
|
|
153
|
-
export const beforeIf = createTypeChecker([
|
|
154
|
-
['-: -> !', isInsideArray],
|
|
155
|
-
['-: parentPath ->', isCoupleLines],
|
|
156
|
-
]);
|
|
157
|
-
```
|
|
158
|
-
|
|
159
87
|
## apply-breakline
|
|
160
88
|
|
|
161
89
|
```diff
|
|
@@ -169,15 +97,21 @@ print.breakline();
|
|
|
169
97
|
### β Example of incorrect code
|
|
170
98
|
|
|
171
99
|
```js
|
|
172
|
-
|
|
100
|
+
export const TryStatement = (path, {print}) => {
|
|
101
|
+
print(path.get('block'));
|
|
102
|
+
};
|
|
173
103
|
```
|
|
174
104
|
|
|
175
105
|
### β
Example of correct code
|
|
176
106
|
|
|
177
107
|
```js
|
|
178
|
-
print
|
|
108
|
+
export const TryStatement = (path, {print}) => {
|
|
109
|
+
print('__block');
|
|
110
|
+
};
|
|
179
111
|
```
|
|
180
112
|
|
|
113
|
+
The rule changes only the `print` of a printer visitor (a parameter). Imported `print` of `putout` needs a path and stays as is.
|
|
114
|
+
|
|
181
115
|
## apply-create-test-url
|
|
182
116
|
|
|
183
117
|
Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/ddf1425ace2a53e9010b82ded1dd1012/3e56365b58d01ebe8abba46caf04ed5e51043feb).
|
|
@@ -198,34 +132,6 @@ import {createTest} from '#test';
|
|
|
198
132
|
const {test, fixture} = createTest(import.meta.url);
|
|
199
133
|
```
|
|
200
134
|
|
|
201
|
-
## add-missing-tuple-to-type-checker
|
|
202
|
-
|
|
203
|
-
Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/9fdfda423df3af9b0f08541710706299/0259bba117997861fe7573bad5477282f4df8554).
|
|
204
|
-
|
|
205
|
-
### β Example of incorrect code
|
|
206
|
-
|
|
207
|
-
```js
|
|
208
|
-
export const beforeIf = createTypeChecker([
|
|
209
|
-
'- : -> !StringLiteral',
|
|
210
|
-
'- : -> BlockStatement',
|
|
211
|
-
'- : -> WrongType',
|
|
212
|
-
['- : ->', isBlockStatement],
|
|
213
|
-
['-', isBlockStatement],
|
|
214
|
-
]);
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
### β
Example of correct code
|
|
218
|
-
|
|
219
|
-
```js
|
|
220
|
-
export const beforeIf = createTypeChecker([
|
|
221
|
-
['- : -> !StringLiteral'],
|
|
222
|
-
['- : -> BlockStatement'],
|
|
223
|
-
['- : -> WrongType'],
|
|
224
|
-
['- : ->', isBlockStatement],
|
|
225
|
-
['-', isBlockStatement],
|
|
226
|
-
]);
|
|
227
|
-
```
|
|
228
|
-
|
|
229
135
|
## apply-printer-declarations
|
|
230
136
|
|
|
231
137
|
Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/2fc66c476a235eb25f47e55fd7b33042/b0371fe2dd62e8f9fe5ce1fff6d352386e69fcc6).
|
|
@@ -266,77 +172,6 @@ Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/8a88fec812
|
|
|
266
172
|
+const {isIdentifier} = types;
|
|
267
173
|
```
|
|
268
174
|
|
|
269
|
-
## check-if-success-possible-in-type-checker
|
|
270
|
-
|
|
271
|
-
Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/4164addec1e1b2bb93ad7caf3ed13ad8/b04dc172f4094ea6b6902ec54deee779aba6b944).
|
|
272
|
-
When you have only negative branch defined in type checker it never never succeeds (`+`), and always returns false.
|
|
273
|
-
|
|
274
|
-
Consider adding success branch, or remove type checker.
|
|
275
|
-
|
|
276
|
-
βοΈ *This rule has no autofix, because most likely tests will fail after auto fix,
|
|
277
|
-
and instead of observing code with a problem, you will first see failed tests,
|
|
278
|
-
and then after some searches determine that there is a wrong auto fix.*
|
|
279
|
-
|
|
280
|
-
### β Example of incorrect code
|
|
281
|
-
|
|
282
|
-
```js
|
|
283
|
-
const isSimple = createTypeChecker([
|
|
284
|
-
'-: -> SpreadElement',
|
|
285
|
-
'-: -> Identifier',
|
|
286
|
-
'-: -> !CallExpression',
|
|
287
|
-
]);
|
|
288
|
-
|
|
289
|
-
const isSimpleAfterObject = createTypeChecker([
|
|
290
|
-
['-', isSimple],
|
|
291
|
-
['-', callWithNext(isObjectExpression)],
|
|
292
|
-
['-', callWithPrev(isObjectExpression)],
|
|
293
|
-
]);
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
### β
Example of correct code
|
|
297
|
-
|
|
298
|
-
Possible fix:
|
|
299
|
-
|
|
300
|
-
```js
|
|
301
|
-
const isSimple = createTypeChecker([
|
|
302
|
-
'-: -> SpreadElement',
|
|
303
|
-
'-: -> Identifier',
|
|
304
|
-
'+: -> !CallExpression',
|
|
305
|
-
]);
|
|
306
|
-
|
|
307
|
-
const isSimpleAfterObject = createTypeChecker([
|
|
308
|
-
['-', isSimple],
|
|
309
|
-
['-', callWithNext(isObjectExpression)],
|
|
310
|
-
['+', callWithPrev(isObjectExpression)],
|
|
311
|
-
]);
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
## check-type-passed-to-type-checker
|
|
315
|
-
|
|
316
|
-
Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/9b35f5f2f23bece832f0f87c929d30e2/b08df8ef8ce6c2a03bceebe6119846c45a78a119).
|
|
317
|
-
|
|
318
|
-
βοΈ *This rule has no autofix, because most likely tests will fail after auto fix,
|
|
319
|
-
and instead of observing code with a problem, you will first see failed tests,
|
|
320
|
-
and then after some searches determine that there is a wrong auto fix.*
|
|
321
|
-
|
|
322
|
-
### β Example of incorrect code
|
|
323
|
-
|
|
324
|
-
```js
|
|
325
|
-
export const beforeIf = createTypeChecker([
|
|
326
|
-
['- : -> WrongType'],
|
|
327
|
-
]);
|
|
328
|
-
```
|
|
329
|
-
|
|
330
|
-
### β
Example of correct code
|
|
331
|
-
|
|
332
|
-
Here is possible correct code:
|
|
333
|
-
|
|
334
|
-
```js
|
|
335
|
-
export const beforeIf = createTypeChecker([
|
|
336
|
-
['- : -> Identifier'],
|
|
337
|
-
]);
|
|
338
|
-
```
|
|
339
|
-
|
|
340
175
|
## declare
|
|
341
176
|
|
|
342
177
|
### β Example of incorrect code
|
|
@@ -393,30 +228,6 @@ export const FunctionDeclaration = {
|
|
|
393
228
|
};
|
|
394
229
|
```
|
|
395
230
|
|
|
396
|
-
## merge-tuple-of-type-checker
|
|
397
|
-
|
|
398
|
-
Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/7351b8359ac3da967e9b4b80d49b51da/74de1543f6e129f6e22f38e2eb597abce6c122a6).
|
|
399
|
-
|
|
400
|
-
### β Example of incorrect code
|
|
401
|
-
|
|
402
|
-
```js
|
|
403
|
-
export const isNewlineAfterComma = createTypeChecker([
|
|
404
|
-
['+: -> !', isObjectExpression],
|
|
405
|
-
['+: ->', isStringLiteral],
|
|
406
|
-
['+', isStringLiteral],
|
|
407
|
-
]);
|
|
408
|
-
```
|
|
409
|
-
|
|
410
|
-
### β
Example of correct code
|
|
411
|
-
|
|
412
|
-
```js
|
|
413
|
-
export const isNewlineAfterComma = createTypeChecker([
|
|
414
|
-
['+: -> !ObjectExpression'],
|
|
415
|
-
['+: -> StringLiteral'],
|
|
416
|
-
['+: StringLiteral'],
|
|
417
|
-
]);
|
|
418
|
-
```
|
|
419
|
-
|
|
420
231
|
## remove-args
|
|
421
232
|
|
|
422
233
|
### β Example of incorrect code
|
|
@@ -444,70 +255,6 @@ print.indent();
|
|
|
444
255
|
-});
|
|
445
256
|
```
|
|
446
257
|
|
|
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
258
|
## remove-useless-maybe
|
|
512
259
|
|
|
513
260
|
Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d448a928400ff37043ae03510ce7c85c/db1a758809e8759f591533f9ef92bef1188d32b0).
|
|
@@ -526,168 +273,6 @@ maybe.indent(wasNewline);
|
|
|
526
273
|
print.newline();
|
|
527
274
|
```
|
|
528
275
|
|
|
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
|
-
|
|
615
|
-
## reverse-comparison-in-type-checker
|
|
616
|
-
|
|
617
|
-
Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/ae2335d32022de240e918ce077144767/f25c5a11f746fe532f81adede991286cb77d1b11).
|
|
618
|
-
|
|
619
|
-
### β Example of incorrect code
|
|
620
|
-
|
|
621
|
-
```js
|
|
622
|
-
const isMoreThenMaxElementLengthInOneLine = createTypeChecker([
|
|
623
|
-
['-: node.elements.length -> !', '<', 2],
|
|
624
|
-
['-: node.elements.length -> !', '>', 2],
|
|
625
|
-
['-: node.elements.length -> !', '>=', 2],
|
|
626
|
-
['-: node.elements.length -> !', '<=', 2],
|
|
627
|
-
]);
|
|
628
|
-
```
|
|
629
|
-
|
|
630
|
-
### β
Example of correct code
|
|
631
|
-
|
|
632
|
-
```js
|
|
633
|
-
const isMoreThenMaxElementLengthInOneLine = createTypeChecker([
|
|
634
|
-
['-: node.elements.length', '>=', 2],
|
|
635
|
-
['-: node.elements.length', '<=', 2],
|
|
636
|
-
['-: node.elements.length', '<', 2],
|
|
637
|
-
['-: node.elements.length', '>', 2],
|
|
638
|
-
]);
|
|
639
|
-
```
|
|
640
|
-
|
|
641
|
-
## reverse-comparison-in-type-checker
|
|
642
|
-
|
|
643
|
-
Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/be2bb33f5c7ac7b687c1fa856704bc73/e57fa5a3ded571adca03f5bdeb5a0f63a594aa81).
|
|
644
|
-
|
|
645
|
-
### β Example of incorrect code
|
|
646
|
-
|
|
647
|
-
```js
|
|
648
|
-
export const ExpressionStatement = {
|
|
649
|
-
print(path, {indent, print}) {
|
|
650
|
-
indent();
|
|
651
|
-
print('__expression');
|
|
652
|
-
print.newline();
|
|
653
|
-
},
|
|
654
|
-
};
|
|
655
|
-
```
|
|
656
|
-
|
|
657
|
-
### β
Example of correct code
|
|
658
|
-
|
|
659
|
-
```js
|
|
660
|
-
export const ExpressionStatement = (path, {indent, print}) => {
|
|
661
|
-
indent();
|
|
662
|
-
print('__expression');
|
|
663
|
-
print.newline();
|
|
664
|
-
};
|
|
665
|
-
```
|
|
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
|
-
|
|
691
276
|
## License
|
|
692
277
|
|
|
693
278
|
MIT
|
|
@@ -1,7 +1,18 @@
|
|
|
1
|
+
import {operator} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {getBinding} = operator;
|
|
1
4
|
const {assign} = Object;
|
|
2
5
|
|
|
3
6
|
export const report = () => `Use print('__path') instead of path.get(__path)`;
|
|
4
7
|
|
|
8
|
+
// 'print' of '@putout/printer' visitor is a param: '(path, {print}) => {}'
|
|
9
|
+
// 'print' of 'putout' is imported and needs a path
|
|
10
|
+
const isPrintParam = (path) => getBinding(path, 'print')?.kind === 'param';
|
|
11
|
+
|
|
12
|
+
export const match = () => ({
|
|
13
|
+
'print(path.get(__a))': (vars, path) => isPrintParam(path),
|
|
14
|
+
});
|
|
15
|
+
|
|
5
16
|
export const replace = () => ({
|
|
6
17
|
'print(path.get(__a))': ({__a}) => {
|
|
7
18
|
const {raw, value} = __a;
|
package/lib/index.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
import * as applyBooleanOperatorToTypeChecker from './apply-boolean-operator-to-type-checker/index.js';
|
|
2
1
|
import * as declareNearby from './declare-nearby/index.js';
|
|
3
2
|
import * as applyPrinterDeclarations from './apply-printer-declarations/index.js';
|
|
4
3
|
import * as removeUselessPrint from './remove-useless-print/index.js';
|
|
5
|
-
import * as addMissingArrowToTypeChecker from './add-missing-arrow-to-type-checker/index.js';
|
|
6
|
-
import * as removeUselessArrowFromTypeChecker from './remove-useless-arrow-from-type-checker/index.js';
|
|
7
|
-
import * as removeUselessPathFromTypeChecker from './remove-useless-path-from-type-checker/index.js';
|
|
8
|
-
import * as reverseComparisonInTypeChecker from './reverse-comparison-in-type-checker/index.js';
|
|
9
|
-
import * as removeUselessNotFromTypeChecker from './remove-useless-not-from-type-checker/index.js';
|
|
10
|
-
import * as removeUselessColonFromTypeChecker from './remove-useless-colon-from-type-checker/index.js';
|
|
11
|
-
import * as addMissingColonToTypeChecker from './add-missing-colon-to-type-checker/index.js';
|
|
12
|
-
import * as mergeTuplesOfTypeCheckers from './merge-tuples-of-type-checkers/index.js';
|
|
13
|
-
import * as checkIfSuccessPossibleInTypeChecker from './check-if-success-possible-in-type-checker/index.js';
|
|
14
|
-
import * as removeUselessTuplesFromTypeChecker from './remove-useless-tuples-from-type-checker/index.js';
|
|
15
|
-
import * as addMissingTuplesToTypeChecker from './add-missing-tuples-to-type-checker/index.js';
|
|
16
|
-
import * as checkTypePassedToTypeChecker from './check-type-passed-to-type-checker/index.js';
|
|
17
|
-
import * as removeUselessSpacesFromTypeChecker from './remove-useless-spaces-from-type-checker/index.js';
|
|
18
|
-
import * as addMissingSpacesToTypeChecker from './add-missing-spaces-to-type-checker/index.js';
|
|
19
|
-
import * as removeTrailingSpacesFromTypeChecker from './remove-trailing-spaces-from-type-checker/index.js';
|
|
20
4
|
import * as removeUselessMaybe from './remove-useless-maybe/index.js';
|
|
21
5
|
import * as applyCreateTestUrl from './apply-create-test-url/index.js';
|
|
22
6
|
import * as removeArgs from './remove-args/index.js';
|
|
@@ -40,22 +24,6 @@ export const rules = {
|
|
|
40
24
|
'remove-legacy-test-declaration': removeLegacyTestDeclaration,
|
|
41
25
|
'remove-args': removeArgs,
|
|
42
26
|
'remove-useless-maybe': removeUselessMaybe,
|
|
43
|
-
'remove-trailing-spaces-from-type-checker': removeTrailingSpacesFromTypeChecker,
|
|
44
|
-
'add-missing-spaces-to-type-checker': addMissingSpacesToTypeChecker,
|
|
45
|
-
'remove-useless-spaces-from-type-checker': removeUselessSpacesFromTypeChecker,
|
|
46
|
-
'check-type-passed-to-type-checker': checkTypePassedToTypeChecker,
|
|
47
|
-
'add-missing-tuples-to-type-checker': addMissingTuplesToTypeChecker,
|
|
48
|
-
'remove-useless-tuples-from-type-checker': removeUselessTuplesFromTypeChecker,
|
|
49
|
-
'check-if-success-possible-in-type-checker': checkIfSuccessPossibleInTypeChecker,
|
|
50
|
-
'merge-tuples-of-type-checkers': mergeTuplesOfTypeCheckers,
|
|
51
|
-
'add-missing-colon-to-type-checker': addMissingColonToTypeChecker,
|
|
52
|
-
'remove-useless-colon-from-type-checker': removeUselessColonFromTypeChecker,
|
|
53
|
-
'remove-useless-not-from-type-checker': removeUselessNotFromTypeChecker,
|
|
54
|
-
'reverse-comparison-in-type-checker': reverseComparisonInTypeChecker,
|
|
55
|
-
'remove-useless-path-from-type-checker': removeUselessPathFromTypeChecker,
|
|
56
|
-
'remove-useless-arrow-from-type-checker': removeUselessArrowFromTypeChecker,
|
|
57
|
-
'add-missing-arrow-to-type-checker': addMissingArrowToTypeChecker,
|
|
58
27
|
'remove-useless-print': removeUselessPrint,
|
|
59
28
|
'declare-nearby': declareNearby,
|
|
60
|
-
'apply-boolean-operator-to-type-checker': applyBooleanOperatorToTypeChecker,
|
|
61
29
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-printer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.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",
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import {operator, types} from 'putout';
|
|
2
|
-
import {isTypeExists} from '#types';
|
|
3
|
-
|
|
4
|
-
const {
|
|
5
|
-
isIdentifier,
|
|
6
|
-
isCallExpression,
|
|
7
|
-
} = types;
|
|
8
|
-
|
|
9
|
-
const {setLiteralValue} = operator;
|
|
10
|
-
|
|
11
|
-
export const report = ({path, where}) => {
|
|
12
|
-
const {value} = path.node;
|
|
13
|
-
const withSpaces = addArrow(value, where);
|
|
14
|
-
|
|
15
|
-
return `Add missing arrow: '${value}' -> '${withSpaces}'`;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const fix = ({path, where}) => {
|
|
19
|
-
const {value} = path.node;
|
|
20
|
-
setLiteralValue(path, addArrow(value, where));
|
|
21
|
-
};
|
|
22
|
-
export const traverse = ({push}) => ({
|
|
23
|
-
StringLiteral(path) {
|
|
24
|
-
const call = path.find(isCallExpression);
|
|
25
|
-
|
|
26
|
-
if (!call)
|
|
27
|
-
return;
|
|
28
|
-
|
|
29
|
-
if (!isIdentifier(call.node.callee, {name: 'createTypeChecker'}))
|
|
30
|
-
return;
|
|
31
|
-
|
|
32
|
-
const {value} = path.node;
|
|
33
|
-
const where = createWhere(value);
|
|
34
|
-
|
|
35
|
-
if (where.length)
|
|
36
|
-
push({
|
|
37
|
-
path,
|
|
38
|
-
where,
|
|
39
|
-
});
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
function createWhere(value) {
|
|
44
|
-
const where = [];
|
|
45
|
-
|
|
46
|
-
if (value.startsWith('+: !') && !value.includes('->'))
|
|
47
|
-
where.push('after-colon');
|
|
48
|
-
|
|
49
|
-
if (value.startsWith('-: !') && !value.includes('->'))
|
|
50
|
-
where.push('after-colon');
|
|
51
|
-
|
|
52
|
-
if (value.startsWith('+: ') && !value.includes('->')) {
|
|
53
|
-
const type = value.replace('+: ', '');
|
|
54
|
-
|
|
55
|
-
if (isTypeExists(type))
|
|
56
|
-
where.push('before-type');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (value.startsWith('-: ') && !value.includes('->')) {
|
|
60
|
-
const type = value.replace('-: ', '');
|
|
61
|
-
|
|
62
|
-
if (isTypeExists(type))
|
|
63
|
-
where.push('before-type');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return where;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function addArrow(value, where) {
|
|
70
|
-
if (where.includes('after-colon'))
|
|
71
|
-
value = value.replace(': !', ': -> !');
|
|
72
|
-
|
|
73
|
-
if (where.includes('before-type'))
|
|
74
|
-
value = value.replace(': ', ': -> ');
|
|
75
|
-
|
|
76
|
-
return value;
|
|
77
|
-
}
|