@putout/plugin-printer 8.20.0 → 8.21.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 +32 -0
- package/lib/apply-printer-declarations/index.js +40 -0
- package/lib/index.js +6 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ npm i @putout/plugin-printer -D
|
|
|
21
21
|
- ✅ [apply-computed-print](#apply-computed-print);
|
|
22
22
|
- ✅ [apply-create-test-url](#apply-create-test-url);
|
|
23
23
|
- ✅ [apply-linebreak](#apply-linebreak);
|
|
24
|
+
- ✅ [apply-printer-declarations](#apply-printer-declarations);
|
|
24
25
|
- ✅ [apply-types](#apply-types);
|
|
25
26
|
- ✅ [check-type-passed-to-type-checker](#check-type-passed-to-type-checker);
|
|
26
27
|
- ✅ [check-if-success-possible-in-type-checker](#check-if-success-possible-in-type-checker);
|
|
@@ -52,6 +53,7 @@ npm i @putout/plugin-printer -D
|
|
|
52
53
|
"printer/apply-linebreak": "on",
|
|
53
54
|
"printer/apply-computed-print": "on",
|
|
54
55
|
"printer/apply-create-test-url": "on",
|
|
56
|
+
"printer/apply-printer-declarations": "on",
|
|
55
57
|
"printer/apply-types": "on",
|
|
56
58
|
"printer/check-type-passed-to-type-checker": "on",
|
|
57
59
|
"printer/check-if-success-possible-in-type-checker": "on",
|
|
@@ -88,6 +90,36 @@ print.breakline();
|
|
|
88
90
|
print.linebreak();
|
|
89
91
|
```
|
|
90
92
|
|
|
93
|
+
## apply-printer-declarations
|
|
94
|
+
|
|
95
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/2fc66c476a235eb25f47e55fd7b33042/b0371fe2dd62e8f9fe5ce1fff6d352386e69fcc6).
|
|
96
|
+
|
|
97
|
+
### ❌ Example of incorrect code
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
export const ExportNamedDeclaration = (path, printer, {indent}) => {
|
|
101
|
+
const {print, write} = printer;
|
|
102
|
+
const {leadingComments} = path.node;
|
|
103
|
+
|
|
104
|
+
indent();
|
|
105
|
+
};
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### ✅ Example of correct code
|
|
109
|
+
|
|
110
|
+
```js
|
|
111
|
+
export const ExportNamedDeclaration = (path, printer) => {
|
|
112
|
+
const {leadingComments} = path.node;
|
|
113
|
+
const {
|
|
114
|
+
print,
|
|
115
|
+
write,
|
|
116
|
+
indent,
|
|
117
|
+
} = printer;
|
|
118
|
+
|
|
119
|
+
indent();
|
|
120
|
+
};
|
|
121
|
+
```
|
|
122
|
+
|
|
91
123
|
## apply-types
|
|
92
124
|
|
|
93
125
|
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/8a88fec812a52e302cf7b191eca2f49e/474ca87860d2eab755373ba9dc8b12efc4a80252).
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {types, operator} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {superTraverse} = operator;
|
|
4
|
+
const {objectProperty, identifier} = types;
|
|
5
|
+
|
|
6
|
+
const {assign} = Object;
|
|
7
|
+
|
|
8
|
+
const names = [
|
|
9
|
+
'indent',
|
|
10
|
+
'write',
|
|
11
|
+
'print',
|
|
12
|
+
'maybe',
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
export const report = () => `Destructure from 'printer' variable instead of argument`;
|
|
16
|
+
|
|
17
|
+
export const replace = () => {
|
|
18
|
+
const visitors = {};
|
|
19
|
+
|
|
20
|
+
for (const name of names) {
|
|
21
|
+
assign(visitors, createVisitor(name));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return visitors;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const createVisitor = (name) => ({
|
|
28
|
+
[`(path, printer, {${name}}) => {__body}`]: (vars, path) => {
|
|
29
|
+
const id = identifier(String(name));
|
|
30
|
+
|
|
31
|
+
superTraverse(path, {
|
|
32
|
+
'const __object = printer': (path) => {
|
|
33
|
+
const {properties} = path.node.declarations[0].id;
|
|
34
|
+
properties.push(objectProperty(id, id));
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return '(path, printer) => {__body}';
|
|
39
|
+
},
|
|
40
|
+
});
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as applyPrinterDeclarations from './apply-printer-declarations/index.js';
|
|
1
2
|
import * as removeUselessPrint from './remove-useless-print/index.js';
|
|
2
3
|
import * as addMissingArrowToTypeChecker from './add-missing-arrow-to-type-checker/index.js';
|
|
3
4
|
import * as removeUselessArrowFromTypeChecker from './remove-useless-arrow-from-type-checker/index.js';
|
|
@@ -26,15 +27,16 @@ import * as applyTypes from './apply-types/index.js';
|
|
|
26
27
|
import * as removeLegacyTestDeclaration from './remove-legacy-test-declaration/index.js';
|
|
27
28
|
|
|
28
29
|
export const rules = {
|
|
29
|
-
'
|
|
30
|
+
'add-args': addArgs,
|
|
31
|
+
'apply-printer-declarations': applyPrinterDeclarations,
|
|
30
32
|
'apply-breakline': applyBreakline,
|
|
31
33
|
'apply-linebreak': applyLinebreak,
|
|
32
34
|
'apply-computed-print': applyComputedPrint,
|
|
33
|
-
'add-args': addArgs,
|
|
34
|
-
declare,
|
|
35
35
|
'apply-types': applyTypes,
|
|
36
|
-
'remove-legacy-test-declaration': removeLegacyTestDeclaration,
|
|
37
36
|
'apply-create-test-url': applyCreateTestUrl,
|
|
37
|
+
declare,
|
|
38
|
+
'remove-legacy-test-declaration': removeLegacyTestDeclaration,
|
|
39
|
+
'remove-args': removeArgs,
|
|
38
40
|
'remove-useless-maybe': removeUselessMaybe,
|
|
39
41
|
'remove-trailing-spaces-from-type-checker': removeTrailingSpacesFromTypeChecker,
|
|
40
42
|
'add-missing-spaces-to-type-checker': addMissingSpacesToTypeChecker,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-printer",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.21.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",
|