@putout/plugin-printer 8.9.0 → 8.10.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 +25 -0
- package/lib/add-missing-colon-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-spaces-to-type-checker](#add-missing-spaces-to-type-checker);
|
|
18
|
+
- ✅ [add-missing-colon-to-type-checker](#add-missing-spaces-to-type-checker);
|
|
18
19
|
- ✅ [add-missing-tuples-to-type-checker](#add-missing-tuples-to-type-checker);
|
|
19
20
|
- ✅ [apply-breakline](#apply-breakline);
|
|
20
21
|
- ✅ [apply-computed-print](#apply-computed-print);
|
|
@@ -39,6 +40,8 @@ npm i @putout/plugin-printer -D
|
|
|
39
40
|
"rules": {
|
|
40
41
|
"printer/add-args": "on",
|
|
41
42
|
"printer/add-missing-tuples-to-type-checker": "on",
|
|
43
|
+
"printer/add-missing-colon-to-type-checker": "on",
|
|
44
|
+
"printer/add-missing-spaces-to-type-checker": "on",
|
|
42
45
|
"printer/apply-breakline": "on",
|
|
43
46
|
"printer/apply-linebreak": "on",
|
|
44
47
|
"printer/apply-computed-print": "on",
|
|
@@ -131,6 +134,28 @@ export const beforeIf = createTypeChecker([
|
|
|
131
134
|
]);
|
|
132
135
|
```
|
|
133
136
|
|
|
137
|
+
## add-missing-colon-to-type-checker
|
|
138
|
+
|
|
139
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/97d38d9bee0586deb8c627c19e399a27/889646df2dcfcfe86f7eb0efb6e3ed5791701f58).
|
|
140
|
+
|
|
141
|
+
### ❌ Example of incorrect code
|
|
142
|
+
|
|
143
|
+
```js
|
|
144
|
+
export const beforeIf = createTypeChecker([
|
|
145
|
+
['+ -> !', isInsideArray],
|
|
146
|
+
['- parentPath ->', isCoupleLines],
|
|
147
|
+
]);
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### ✅ Example of correct code
|
|
151
|
+
|
|
152
|
+
```js
|
|
153
|
+
export const beforeIf = createTypeChecker([
|
|
154
|
+
['+: -> !', isInsideArray],
|
|
155
|
+
['-: parentPath ->', isCoupleLines],
|
|
156
|
+
]);
|
|
157
|
+
```
|
|
158
|
+
|
|
134
159
|
## add-missing-tuple-to-type-checker
|
|
135
160
|
|
|
136
161
|
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/9fdfda423df3af9b0f08541710706299/0259bba117997861fe7573bad5477282f4df8554).
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {operator, types} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
isIdentifier,
|
|
5
|
+
isCallExpression,
|
|
6
|
+
} = types;
|
|
7
|
+
|
|
8
|
+
const {setLiteralValue} = operator;
|
|
9
|
+
|
|
10
|
+
export const report = ({path, where}) => {
|
|
11
|
+
const {value} = path.node;
|
|
12
|
+
const withColon = addColon(value, where);
|
|
13
|
+
|
|
14
|
+
return `Add missing colon: '${value}' -> '${withColon}'`;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const fix = ({path, where}) => {
|
|
18
|
+
const {value} = path.node;
|
|
19
|
+
setLiteralValue(path, addColon(value, where));
|
|
20
|
+
};
|
|
21
|
+
export const traverse = ({push}) => ({
|
|
22
|
+
StringLiteral(path) {
|
|
23
|
+
const call = path.find(isCallExpression);
|
|
24
|
+
|
|
25
|
+
if (!call)
|
|
26
|
+
return;
|
|
27
|
+
|
|
28
|
+
if (!isIdentifier(call.node.callee, {name: 'createTypeChecker'}))
|
|
29
|
+
return;
|
|
30
|
+
|
|
31
|
+
const {value} = path.node;
|
|
32
|
+
const where = createWhere(value);
|
|
33
|
+
|
|
34
|
+
if (where.length)
|
|
35
|
+
push({
|
|
36
|
+
path,
|
|
37
|
+
where,
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
function createWhere(value) {
|
|
43
|
+
const where = [];
|
|
44
|
+
|
|
45
|
+
if (value.length === 1)
|
|
46
|
+
return where;
|
|
47
|
+
|
|
48
|
+
if (value.startsWith('+') && !value.includes(':'))
|
|
49
|
+
where.push('after-plus');
|
|
50
|
+
|
|
51
|
+
if (value.startsWith('-') && !value.includes('-:'))
|
|
52
|
+
where.push('after-minus');
|
|
53
|
+
|
|
54
|
+
return where;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function addColon(value, where) {
|
|
58
|
+
if (where.includes('after-plus'))
|
|
59
|
+
value = value.replace('+', '+:');
|
|
60
|
+
|
|
61
|
+
if (where.includes('after-minus'))
|
|
62
|
+
value = value.replace('-', '-:');
|
|
63
|
+
|
|
64
|
+
return value;
|
|
65
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as addMissingColonToTypeChecker from './add-missing-colon-to-type-checker/index.js';
|
|
1
2
|
import * as mergeTuplesOfTypeCheckers from './merge-tuples-of-type-checkers/index.js';
|
|
2
3
|
import * as checkIfSuccessPossibleInTypeChecker from './check-if-success-possible-in-type-checker/index.js';
|
|
3
4
|
import * as removeUselessTuplesFromTypeChecker from './remove-useless-tuples-from-type-checker/index.js';
|
|
@@ -36,4 +37,5 @@ export const rules = {
|
|
|
36
37
|
'remove-useless-tuples-from-type-checker': removeUselessTuplesFromTypeChecker,
|
|
37
38
|
'check-if-success-possible-in-type-checker': checkIfSuccessPossibleInTypeChecker,
|
|
38
39
|
'merge-tuples-of-type-checkers': mergeTuplesOfTypeCheckers,
|
|
40
|
+
'add-missing-colon-to-type-checker': addMissingColonToTypeChecker,
|
|
39
41
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-printer",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.10.1",
|
|
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",
|