@putout/plugin-printer 8.5.2 → 8.6.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
|
@@ -14,8 +14,8 @@ npm i @putout/plugin-printer -D
|
|
|
14
14
|
## Rules
|
|
15
15
|
|
|
16
16
|
- ✅ [add-args](#add-args);
|
|
17
|
-
- ✅ [add-missing-
|
|
18
|
-
- ✅ [add-missing-
|
|
17
|
+
- ✅ [add-missing-spaces-to-type-checker](#add-missing-spaces-to-type-checker);
|
|
18
|
+
- ✅ [add-missing-tuples-to-type-checker](#add-missing-tuples-to-type-checker);
|
|
19
19
|
- ✅ [apply-breakline](#apply-breakline);
|
|
20
20
|
- ✅ [apply-computed-print](#apply-computed-print);
|
|
21
21
|
- ✅ [apply-create-test-url](#apply-create-test-url);
|
|
@@ -28,6 +28,7 @@ npm i @putout/plugin-printer -D
|
|
|
28
28
|
- ✅ [remove-legacy-test-declaration](#remove-legacy-test-declaration);
|
|
29
29
|
- ✅ [remove-trailing-spaces-from-type-checker](#remove-trailing-spaces-from-type-checker)
|
|
30
30
|
- ✅ [remove-useless-spaces-from-type-checker](#remove-useless-spaces-from-type-checker)
|
|
31
|
+
- ✅ [remove-useless-tuples-from-type-checker](#remove-useless-tuples-from-type-checker)
|
|
31
32
|
|
|
32
33
|
## Config
|
|
33
34
|
|
|
@@ -35,7 +36,7 @@ npm i @putout/plugin-printer -D
|
|
|
35
36
|
{
|
|
36
37
|
"rules": {
|
|
37
38
|
"printer/add-args": "on",
|
|
38
|
-
"printer/add-missing-
|
|
39
|
+
"printer/add-missing-tuples-to-type-checker": "on",
|
|
39
40
|
"printer/apply-breakline": "on",
|
|
40
41
|
"printer/apply-linebreak": "on",
|
|
41
42
|
"printer/apply-computed-print": "on",
|
|
@@ -46,7 +47,8 @@ npm i @putout/plugin-printer -D
|
|
|
46
47
|
"printer/remove-args": "on",
|
|
47
48
|
"printer/remove-useless-maybe": "on",
|
|
48
49
|
"printer/remove-trailing-spaces-from-type-checker": "on",
|
|
49
|
-
"printer/remove-useless-spaces-from-type-checker": "on"
|
|
50
|
+
"printer/remove-useless-spaces-from-type-checker": "on",
|
|
51
|
+
"printer/remove-useless-tuples-from-type-checker": "on"
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
54
|
```
|
|
@@ -103,7 +105,7 @@ module.exports = {
|
|
|
103
105
|
};
|
|
104
106
|
```
|
|
105
107
|
|
|
106
|
-
## add-missing-
|
|
108
|
+
## add-missing-spaces-to-type-checker
|
|
107
109
|
|
|
108
110
|
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/2451cd51ebd3dfd20c32b6d22ca176b7/bd593860ff4bb2d66e06cf95bbe103cb1203129d).
|
|
109
111
|
|
|
@@ -239,6 +241,28 @@ export const beforeIf = createTypeChecker([
|
|
|
239
241
|
]);
|
|
240
242
|
```
|
|
241
243
|
|
|
244
|
+
## remove-useless-tuples-from-type-checker
|
|
245
|
+
|
|
246
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/f53f386b607115e0a96f7e294e34761e/cefd72aba4fcade59bbf8faa59739bac5c2fe057).
|
|
247
|
+
|
|
248
|
+
### ❌ Example of incorrect code
|
|
249
|
+
|
|
250
|
+
```js
|
|
251
|
+
export const allStrings = createTypeChecker([
|
|
252
|
+
['- : -> BlockStatement'],
|
|
253
|
+
['- : -> WrongType'],
|
|
254
|
+
]);
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### ✅ Example of correct code
|
|
258
|
+
|
|
259
|
+
```js
|
|
260
|
+
export const allStrings = createTypeChecker([
|
|
261
|
+
'- : -> BlockStatement',
|
|
262
|
+
'- : -> WrongType',
|
|
263
|
+
]);
|
|
264
|
+
```
|
|
265
|
+
|
|
242
266
|
## remove-trailing-spaces-from-type-checker
|
|
243
267
|
|
|
244
268
|
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/91d33e39485c31e76b534ad8447ba4db/abca8d21ad6edc1f6fed23edb05fa166677f11d6).
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as removeUselessTuplesFromTypeChecker from './remove-useless-tuples-from-type-checker/index.js';
|
|
1
2
|
import * as addMissingTuplesToTypeChecker from './add-missing-tuples-to-type-checker/index.js';
|
|
2
3
|
import * as checkTypePassedToTypeChecker from './check-type-passed-to-type-checker/index.js';
|
|
3
4
|
import * as removeUselessSpacesFromTypeChecker from './remove-useless-spaces-from-type-checker/index.js';
|
|
@@ -30,4 +31,5 @@ export const rules = {
|
|
|
30
31
|
'remove-useless-spaces-from-type-checker': removeUselessSpacesFromTypeChecker,
|
|
31
32
|
'check-type-passed-to-type-checker': checkTypePassedToTypeChecker,
|
|
32
33
|
'add-missing-tuples-to-type-checker': addMissingTuplesToTypeChecker,
|
|
34
|
+
'remove-useless-tuples-from-type-checker': removeUselessTuplesFromTypeChecker,
|
|
33
35
|
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {operator, types} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
isStringLiteral,
|
|
5
|
+
isArrayExpression,
|
|
6
|
+
isIdentifier,
|
|
7
|
+
isCallExpression,
|
|
8
|
+
} = types;
|
|
9
|
+
|
|
10
|
+
const {replaceWith} = operator;
|
|
11
|
+
|
|
12
|
+
export const report = (path) => {
|
|
13
|
+
return `Remove useless tuple from: ${path}`;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const fix = (path) => {
|
|
17
|
+
const [element] = path.node.elements;
|
|
18
|
+
replaceWith(path, element);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const traverse = ({push}) => ({
|
|
22
|
+
ArrayExpression(path) {
|
|
23
|
+
const {parentPath} = path;
|
|
24
|
+
|
|
25
|
+
if (!isCallExpression(parentPath))
|
|
26
|
+
return;
|
|
27
|
+
|
|
28
|
+
if (!isIdentifier(parentPath.node.callee, {name: 'createTypeChecker'}))
|
|
29
|
+
return;
|
|
30
|
+
|
|
31
|
+
const elements = path.get('elements');
|
|
32
|
+
|
|
33
|
+
if (isConsistent(elements))
|
|
34
|
+
return;
|
|
35
|
+
|
|
36
|
+
for (const element of elements) {
|
|
37
|
+
if (isArrayExpression(element))
|
|
38
|
+
push(element);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const isTwoElementTuple = (a) => {
|
|
44
|
+
if (!isArrayExpression(a))
|
|
45
|
+
return false;
|
|
46
|
+
|
|
47
|
+
return a.node.elements.length === 2;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
function isConsistent(elements) {
|
|
51
|
+
const stringsCount = elements.filter(isStringLiteral).length;
|
|
52
|
+
|
|
53
|
+
if (elements.length === stringsCount)
|
|
54
|
+
return true;
|
|
55
|
+
|
|
56
|
+
const identifiersCount = elements.filter(isIdentifier).length;
|
|
57
|
+
|
|
58
|
+
if (elements.length === identifiersCount)
|
|
59
|
+
return true;
|
|
60
|
+
|
|
61
|
+
return elements.filter(isTwoElementTuple).length;
|
|
62
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-printer",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.6.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",
|