@putout/plugin-printer 8.19.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 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);
@@ -28,6 +29,7 @@ npm i @putout/plugin-printer -D
28
29
  - ✅ [declare](#declare);
29
30
  - ✅ [remove-args](#remove-args);
30
31
  - ✅ [remove-useless-maybe](#remove-useless-maybe);
32
+ - ✅ [remove-useless-print](#remove-useless-print);
31
33
  - ✅ [remove-legacy-test-declaration](#remove-legacy-test-declaration);
32
34
  - ✅ [remove-trailing-spaces-from-type-checker](#remove-trailing-spaces-from-type-checker);
33
35
  - ✅ [remove-useless-spaces-from-type-checker](#remove-useless-spaces-from-type-checker);
@@ -51,6 +53,7 @@ npm i @putout/plugin-printer -D
51
53
  "printer/apply-linebreak": "on",
52
54
  "printer/apply-computed-print": "on",
53
55
  "printer/apply-create-test-url": "on",
56
+ "printer/apply-printer-declarations": "on",
54
57
  "printer/apply-types": "on",
55
58
  "printer/check-type-passed-to-type-checker": "on",
56
59
  "printer/check-if-success-possible-in-type-checker": "on",
@@ -65,6 +68,7 @@ npm i @putout/plugin-printer -D
65
68
  "printer/remove-useless-not-from-type-checker": "on",
66
69
  "printer/remove-useless-path-from-type-checker": "on",
67
70
  "printer/remove-useless-tuples-from-type-checker": "on",
71
+ "printer/remove-useless-print": "on",
68
72
  "printer/reverse-comparison-in-type-checker": "on"
69
73
  }
70
74
  }
@@ -86,6 +90,36 @@ print.breakline();
86
90
  print.linebreak();
87
91
  ```
88
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
+
89
123
  ## apply-types
90
124
 
91
125
  Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/8a88fec812a52e302cf7b191eca2f49e/474ca87860d2eab755373ba9dc8b12efc4a80252).
@@ -572,6 +606,32 @@ const isMoreThenMaxElementLengthInOneLine = createTypeChecker([
572
606
  -});
573
607
  ```
574
608
 
609
+ ## reverse-comparison-in-type-checker
610
+
611
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/be2bb33f5c7ac7b687c1fa856704bc73/e57fa5a3ded571adca03f5bdeb5a0f63a594aa81).
612
+
613
+ ### ❌ Example of incorrect code
614
+
615
+ ```js
616
+ export const ExpressionStatement = {
617
+ print(path, {indent, print}) {
618
+ indent();
619
+ print('__expression');
620
+ print.newline();
621
+ },
622
+ };
623
+ ```
624
+
625
+ ### ✅ Example of correct code
626
+
627
+ ```js
628
+ export const ExpressionStatement = (path, {indent, print}) => {
629
+ indent();
630
+ print('__expression');
631
+ print.newline();
632
+ };
633
+ ```
634
+
575
635
  ## License
576
636
 
577
637
  MIT
@@ -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,5 @@
1
+ import * as applyPrinterDeclarations from './apply-printer-declarations/index.js';
2
+ import * as removeUselessPrint from './remove-useless-print/index.js';
1
3
  import * as addMissingArrowToTypeChecker from './add-missing-arrow-to-type-checker/index.js';
2
4
  import * as removeUselessArrowFromTypeChecker from './remove-useless-arrow-from-type-checker/index.js';
3
5
  import * as removeUselessPathFromTypeChecker from './remove-useless-path-from-type-checker/index.js';
@@ -25,15 +27,16 @@ import * as applyTypes from './apply-types/index.js';
25
27
  import * as removeLegacyTestDeclaration from './remove-legacy-test-declaration/index.js';
26
28
 
27
29
  export const rules = {
28
- 'remove-args': removeArgs,
30
+ 'add-args': addArgs,
31
+ 'apply-printer-declarations': applyPrinterDeclarations,
29
32
  'apply-breakline': applyBreakline,
30
33
  'apply-linebreak': applyLinebreak,
31
34
  'apply-computed-print': applyComputedPrint,
32
- 'add-args': addArgs,
33
- declare,
34
35
  'apply-types': applyTypes,
35
- 'remove-legacy-test-declaration': removeLegacyTestDeclaration,
36
36
  'apply-create-test-url': applyCreateTestUrl,
37
+ declare,
38
+ 'remove-legacy-test-declaration': removeLegacyTestDeclaration,
39
+ 'remove-args': removeArgs,
37
40
  'remove-useless-maybe': removeUselessMaybe,
38
41
  'remove-trailing-spaces-from-type-checker': removeTrailingSpacesFromTypeChecker,
39
42
  'add-missing-spaces-to-type-checker': addMissingSpacesToTypeChecker,
@@ -50,4 +53,5 @@ export const rules = {
50
53
  'remove-useless-path-from-type-checker': removeUselessPathFromTypeChecker,
51
54
  'remove-useless-arrow-from-type-checker': removeUselessArrowFromTypeChecker,
52
55
  'add-missing-arrow-to-type-checker': addMissingArrowToTypeChecker,
56
+ 'remove-useless-print': removeUselessPrint,
53
57
  };
@@ -0,0 +1,5 @@
1
+ export const report = () => `Avoid 'print' when it is the only method`;
2
+
3
+ export const replace = () => ({
4
+ 'const __a = {print(__args) {__body}}': 'const __a = (__args) => __body',
5
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-printer",
3
- "version": "8.19.0",
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",