@putout/plugin-printer 4.0.0 → 4.1.1

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
@@ -13,6 +13,16 @@ npm i @putout/plugin-printer -D
13
13
 
14
14
  ## Rules
15
15
 
16
+ - ✅ [add-args](#add-args);
17
+ - ✅ [apply-breakline](#apply-breakline);
18
+ - ✅ [apply-linebreak](#apply-linebreak);
19
+ - ✅ [apply-types](#apply-types);
20
+ - ✅ [apply-computed-print](#apply-computed-print);
21
+ - ✅ [declare](#declare);
22
+ - ✅ [remove-args](#remove-args);
23
+
24
+ ## Config
25
+
16
26
  ```json
17
27
  {
18
28
  "rules": {
@@ -42,6 +52,66 @@ print.breakline();
42
52
  print.linebreak();
43
53
  ```
44
54
 
55
+ ## apply-types
56
+
57
+ ```diff
58
+ -const {isIdentifier} = require('@babel/types');
59
+ +const {types} = require('@babel/types');
60
+ +const {isIdentifier} = types;
61
+ ```
62
+
63
+ ## add-args
64
+
65
+ ### ❌ Example of incorrect code
66
+
67
+ ```js
68
+ module.exports = {
69
+ TSPropertySignature(path) {
70
+ const {optional} = path.node;
71
+ print('__key');
72
+ maybe.print(optional, '?');
73
+ },
74
+ };
75
+ ```
76
+
77
+ ### ✅ Example of correct code
78
+
79
+ ```js
80
+ module.exports = {
81
+ TSPropertySignature(path, {print, maybe}) {
82
+ const {optional} = path.node;
83
+ print('__key');
84
+ maybe.print(optional, '?');
85
+ },
86
+ };
87
+ ```
88
+
89
+ ## add-args
90
+
91
+ ### ❌ Example of incorrect code
92
+
93
+ ```js
94
+ module.exports = {
95
+ TSPropertySignature(path) {
96
+ const {optional} = path.node;
97
+ print('__key');
98
+ maybe.print(optional, '?');
99
+ },
100
+ };
101
+ ```
102
+
103
+ ### ✅ Example of correct code
104
+
105
+ ```js
106
+ module.exports = {
107
+ TSPropertySignature(path, {print, maybe}) {
108
+ const {optional} = path.node;
109
+ print('__key');
110
+ maybe.print(optional, '?');
111
+ },
112
+ };
113
+ ```
114
+
45
115
  ## add-args
46
116
 
47
117
  ### ❌ Example of incorrect code
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ const {types} = require('putout');
4
+ const {isObjectPattern} = types;
5
+
6
+ const {keys} = Object;
7
+ const TYPES = keys(types);
8
+
9
+ module.exports.report = () => `require: ('@putout/babel') -> ('putout/babel').types`;
10
+
11
+ module.exports.match = () => ({
12
+ 'const __a = require("@putout/babel")': ({__a}) => {
13
+ if (!isObjectPattern(__a))
14
+ return false;
15
+
16
+ const {properties} = __a;
17
+
18
+ if (properties.length > 1) {
19
+ const [, second] = properties;
20
+ return TYPES.includes(second.value.name);
21
+ }
22
+
23
+ const [first] = properties;
24
+
25
+ return TYPES.includes(first.value.name);
26
+ },
27
+ });
28
+
29
+ module.exports.replace = () => ({
30
+ 'const {types, __a} = require("@putout/babel")': `{
31
+ const {types} = require("@putout/babel");
32
+ const {__a} = types;
33
+ }`,
34
+ 'const __a = require("@putout/babel")': 'const __a = require("@putout/babel").types',
35
+ 'const __a = require("@putout/babel").types': `{
36
+ const {types} = require("@putout/babel");
37
+ const __a = types;
38
+ }`,
39
+ });
package/lib/index.js CHANGED
@@ -6,6 +6,7 @@ const applyLinebreak = require('./apply-linebreak');
6
6
  const applyComputedPrint = require('./apply-computed-print');
7
7
  const addArgs = require('./add-args');
8
8
  const declare = require('./declare');
9
+ const applyTypes = require('./apply-types');
9
10
 
10
11
  module.exports.rules = {
11
12
  'remove-args': removeArgs,
@@ -14,4 +15,5 @@ module.exports.rules = {
14
15
  'apply-computed-print': applyComputedPrint,
15
16
  'add-args': addArgs,
16
17
  declare,
18
+ 'apply-types': applyTypes,
17
19
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-printer",
3
- "version": "4.0.0",
3
+ "version": "4.1.1",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds support of transformations for @putout/printer",