@putout/plugin-printer 8.5.1 → 8.5.2
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 +30 -1
- package/lib/add-missing-tuples-to-type-checker/index.js +65 -0
- package/lib/index.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@ npm i @putout/plugin-printer -D
|
|
|
15
15
|
|
|
16
16
|
- ✅ [add-args](#add-args);
|
|
17
17
|
- ✅ [add-missing-spacess-to-type-checker](#add-missing-spacess-to-type-checker);
|
|
18
|
+
- ✅ [add-missing-tuple-to-type-checker](#add-missing-tuple-to-type-checker);
|
|
18
19
|
- ✅ [apply-breakline](#apply-breakline);
|
|
19
20
|
- ✅ [apply-computed-print](#apply-computed-print);
|
|
20
21
|
- ✅ [apply-create-test-url](#apply-create-test-url);
|
|
@@ -34,7 +35,7 @@ npm i @putout/plugin-printer -D
|
|
|
34
35
|
{
|
|
35
36
|
"rules": {
|
|
36
37
|
"printer/add-args": "on",
|
|
37
|
-
"printer/add-missing-
|
|
38
|
+
"printer/add-missing-tuple-to-type-checker": "on",
|
|
38
39
|
"printer/apply-breakline": "on",
|
|
39
40
|
"printer/apply-linebreak": "on",
|
|
40
41
|
"printer/apply-computed-print": "on",
|
|
@@ -124,6 +125,34 @@ export const beforeIf = createTypeChecker([
|
|
|
124
125
|
]);
|
|
125
126
|
```
|
|
126
127
|
|
|
128
|
+
## add-missing-tuple-to-type-checker
|
|
129
|
+
|
|
130
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/9fdfda423df3af9b0f08541710706299/0259bba117997861fe7573bad5477282f4df8554).
|
|
131
|
+
|
|
132
|
+
### ❌ Example of incorrect code
|
|
133
|
+
|
|
134
|
+
```js
|
|
135
|
+
export const beforeIf = createTypeChecker([
|
|
136
|
+
'- : -> !StringLiteral',
|
|
137
|
+
'- : -> BlockStatement',
|
|
138
|
+
'- : -> WrongType',
|
|
139
|
+
['- : ->', isBlockStatement],
|
|
140
|
+
['-', isBlockStatement],
|
|
141
|
+
]);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### ✅ Example of correct code
|
|
145
|
+
|
|
146
|
+
```js
|
|
147
|
+
export const beforeIf = createTypeChecker([
|
|
148
|
+
['- : -> !StringLiteral'],
|
|
149
|
+
['- : -> BlockStatement'],
|
|
150
|
+
['- : -> WrongType'],
|
|
151
|
+
['- : ->', isBlockStatement],
|
|
152
|
+
['-', isBlockStatement],
|
|
153
|
+
]);
|
|
154
|
+
```
|
|
155
|
+
|
|
127
156
|
## apply-computed-print
|
|
128
157
|
|
|
129
158
|
### ❌ Example of incorrect code
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {operator, types} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
isStringLiteral,
|
|
5
|
+
isArrayExpression,
|
|
6
|
+
isIdentifier,
|
|
7
|
+
isCallExpression,
|
|
8
|
+
arrayExpression,
|
|
9
|
+
stringLiteral,
|
|
10
|
+
} = types;
|
|
11
|
+
|
|
12
|
+
const {replaceWith} = operator;
|
|
13
|
+
|
|
14
|
+
export const report = (path) => {
|
|
15
|
+
return `Add missing tuple around: ${path}`;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const fix = (path) => {
|
|
19
|
+
const {node} = path;
|
|
20
|
+
|
|
21
|
+
if (isIdentifier(path)) {
|
|
22
|
+
replaceWith(path, arrayExpression([stringLiteral('+'), node]));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
replaceWith(path, arrayExpression([node]));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const traverse = ({push}) => ({
|
|
30
|
+
ArrayExpression(path) {
|
|
31
|
+
const {parentPath} = path;
|
|
32
|
+
|
|
33
|
+
if (!isCallExpression(parentPath))
|
|
34
|
+
return;
|
|
35
|
+
|
|
36
|
+
if (!isIdentifier(parentPath.node.callee, {name: 'createTypeChecker'}))
|
|
37
|
+
return;
|
|
38
|
+
|
|
39
|
+
const elements = path.get('elements');
|
|
40
|
+
|
|
41
|
+
if (isConsistent(elements))
|
|
42
|
+
return;
|
|
43
|
+
|
|
44
|
+
for (const element of elements) {
|
|
45
|
+
if (!isArrayExpression(element))
|
|
46
|
+
push(element);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
function isConsistent(elements) {
|
|
52
|
+
const arraysCount = elements.filter(isArrayExpression).length;
|
|
53
|
+
|
|
54
|
+
if (elements.length === arraysCount)
|
|
55
|
+
return true;
|
|
56
|
+
|
|
57
|
+
const stringsCount = elements.filter(isStringLiteral).length;
|
|
58
|
+
|
|
59
|
+
if (elements.length === stringsCount)
|
|
60
|
+
return true;
|
|
61
|
+
|
|
62
|
+
const identifiersCount = elements.filter(isIdentifier).length;
|
|
63
|
+
|
|
64
|
+
return elements.length === identifiersCount;
|
|
65
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as addMissingTuplesToTypeChecker from './add-missing-tuples-to-type-checker/index.js';
|
|
1
2
|
import * as checkTypePassedToTypeChecker from './check-type-passed-to-type-checker/index.js';
|
|
2
3
|
import * as removeUselessSpacesFromTypeChecker from './remove-useless-spaces-from-type-checker/index.js';
|
|
3
4
|
import * as addMissingSpacesToTypeChecker from './add-missing-spaces-to-type-checker/index.js';
|
|
@@ -28,4 +29,5 @@ export const rules = {
|
|
|
28
29
|
'add-missing-spaces-to-type-checker': addMissingSpacesToTypeChecker,
|
|
29
30
|
'remove-useless-spaces-from-type-checker': removeUselessSpacesFromTypeChecker,
|
|
30
31
|
'check-type-passed-to-type-checker': checkTypePassedToTypeChecker,
|
|
32
|
+
'add-missing-tuples-to-type-checker': addMissingTuplesToTypeChecker,
|
|
31
33
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-printer",
|
|
3
|
-
"version": "8.5.
|
|
3
|
+
"version": "8.5.2",
|
|
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",
|