@putout/plugin-printer 8.20.0 → 8.22.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,11 +21,13 @@ 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);
27
28
  - ✅ [merge-tuple-of-type-checker](#merge-tuple-of-type-checker);
28
29
  - ✅ [declare](#declare);
30
+ - ✅ [declare-nearby](#declare-nearby);
29
31
  - ✅ [remove-args](#remove-args);
30
32
  - ✅ [remove-useless-maybe](#remove-useless-maybe);
31
33
  - ✅ [remove-useless-print](#remove-useless-print);
@@ -52,10 +54,12 @@ npm i @putout/plugin-printer -D
52
54
  "printer/apply-linebreak": "on",
53
55
  "printer/apply-computed-print": "on",
54
56
  "printer/apply-create-test-url": "on",
57
+ "printer/apply-printer-declarations": "on",
55
58
  "printer/apply-types": "on",
56
59
  "printer/check-type-passed-to-type-checker": "on",
57
60
  "printer/check-if-success-possible-in-type-checker": "on",
58
61
  "printer/declare": "on",
62
+ "printer/declare-nearby": "on",
59
63
  "printer/merge-tuple-of-type-checker": "on",
60
64
  "printer/remove-args": "on",
61
65
  "printer/remove-useless-maybe": "on",
@@ -88,6 +92,36 @@ print.breakline();
88
92
  print.linebreak();
89
93
  ```
90
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
+
91
125
  ## apply-types
92
126
 
93
127
  Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/8a88fec812a52e302cf7b191eca2f49e/474ca87860d2eab755373ba9dc8b12efc4a80252).
@@ -511,6 +545,34 @@ test('', (t) => {
511
545
  });
512
546
  ```
513
547
 
548
+ ## declare-nearby
549
+
550
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/03d729e40ffd352678cdcc92a1cb7e2d/33a3d522247db4a1dd6d34b035176f26fc020ca8).
551
+
552
+ ### ❌ Example of incorrect code
553
+
554
+ ```js
555
+ export const FunctionDeclaration = {
556
+ print(path, printer, semantics) {
557
+ const {print} = printer;
558
+
559
+ indent();
560
+ },
561
+ };
562
+ ```
563
+
564
+ ### ✅ Example of correct code
565
+
566
+ ```js
567
+ export const FunctionDeclaration = {
568
+ print(path, printer, semantics) {
569
+ const {indent, print} = printer;
570
+
571
+ indent();
572
+ },
573
+ };
574
+ ```
575
+
514
576
  ## merge-tuple-of-type-checker
515
577
 
516
578
  Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/7351b8359ac3da967e9b4b80d49b51da/74de1543f6e129f6e22f38e2eb597abce6c122a6).
@@ -0,0 +1,41 @@
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
+ 'traverse',
13
+ 'maybe',
14
+ ];
15
+
16
+ export const report = () => `Destructure from 'printer' variable instead of argument`;
17
+
18
+ export const replace = () => {
19
+ const visitors = {};
20
+
21
+ for (const name of names) {
22
+ assign(visitors, createVisitor(name));
23
+ }
24
+
25
+ return visitors;
26
+ };
27
+
28
+ const createVisitor = (name) => ({
29
+ [`(path, printer, {${name}}) => {__body}`]: (vars, path) => {
30
+ const id = identifier(String(name));
31
+
32
+ superTraverse(path, {
33
+ 'const __object = printer': (path) => {
34
+ const {properties} = path.node.declarations[0].id;
35
+ properties.push(objectProperty(id, id));
36
+ },
37
+ });
38
+
39
+ return '(path, printer) => {__body}';
40
+ },
41
+ });
@@ -0,0 +1,11 @@
1
+ const options = {
2
+ nearby: true,
3
+ };
4
+
5
+ export const declare = () => ({
6
+ indent: ['const {indent} = printer', options],
7
+ print: ['const {print} = printer', options],
8
+ write: ['const {write} = printer', options],
9
+ traverse: ['const {traverse} = printer', options],
10
+ maybe: ['const {maybe} = printer', options],
11
+ });
package/lib/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ import * as declareNearby from './declare-nearby/index.js';
2
+ import * as applyPrinterDeclarations from './apply-printer-declarations/index.js';
1
3
  import * as removeUselessPrint from './remove-useless-print/index.js';
2
4
  import * as addMissingArrowToTypeChecker from './add-missing-arrow-to-type-checker/index.js';
3
5
  import * as removeUselessArrowFromTypeChecker from './remove-useless-arrow-from-type-checker/index.js';
@@ -26,15 +28,16 @@ import * as applyTypes from './apply-types/index.js';
26
28
  import * as removeLegacyTestDeclaration from './remove-legacy-test-declaration/index.js';
27
29
 
28
30
  export const rules = {
29
- 'remove-args': removeArgs,
31
+ 'add-args': addArgs,
32
+ 'apply-printer-declarations': applyPrinterDeclarations,
30
33
  'apply-breakline': applyBreakline,
31
34
  'apply-linebreak': applyLinebreak,
32
35
  'apply-computed-print': applyComputedPrint,
33
- 'add-args': addArgs,
34
- declare,
35
36
  'apply-types': applyTypes,
36
- 'remove-legacy-test-declaration': removeLegacyTestDeclaration,
37
37
  'apply-create-test-url': applyCreateTestUrl,
38
+ declare,
39
+ 'remove-legacy-test-declaration': removeLegacyTestDeclaration,
40
+ 'remove-args': removeArgs,
38
41
  'remove-useless-maybe': removeUselessMaybe,
39
42
  'remove-trailing-spaces-from-type-checker': removeTrailingSpacesFromTypeChecker,
40
43
  'add-missing-spaces-to-type-checker': addMissingSpacesToTypeChecker,
@@ -52,4 +55,5 @@ export const rules = {
52
55
  'remove-useless-arrow-from-type-checker': removeUselessArrowFromTypeChecker,
53
56
  'add-missing-arrow-to-type-checker': addMissingArrowToTypeChecker,
54
57
  'remove-useless-print': removeUselessPrint,
58
+ 'declare-nearby': declareNearby,
55
59
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-printer",
3
- "version": "8.20.0",
3
+ "version": "8.22.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",