@putout/plugin-printer 8.17.1 → 8.18.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.
|
@@ -0,0 +1,59 @@
|
|
|
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 withSpaces = addArrow(value, where);
|
|
13
|
+
|
|
14
|
+
return `Add missing arrow: '${value}' -> '${withSpaces}'`;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const fix = ({path, where}) => {
|
|
18
|
+
const {value} = path.node;
|
|
19
|
+
setLiteralValue(path, addArrow(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.startsWith('+: !') && !value.includes('->'))
|
|
46
|
+
where.push('after-colon');
|
|
47
|
+
|
|
48
|
+
if (value.startsWith('-: !') && !value.includes('->'))
|
|
49
|
+
where.push('after-colon');
|
|
50
|
+
|
|
51
|
+
return where;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function addArrow(value, where) {
|
|
55
|
+
if (where.includes('after-colon'))
|
|
56
|
+
value = value.replace(': !', ': -> !');
|
|
57
|
+
|
|
58
|
+
return value;
|
|
59
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as addMissingArrowToTypeChecker from './add-missing-arrow-to-type-checker/index.js';
|
|
1
2
|
import * as removeUselessArrowFromTypeChecker from './remove-useless-arrow-from-type-checker/index.js';
|
|
2
3
|
import * as removeUselessPathFromTypeChecker from './remove-useless-path-from-type-checker/index.js';
|
|
3
4
|
import * as reverseComparisonInTypeChecker from './reverse-comparison-in-type-checker/index.js';
|
|
@@ -48,4 +49,5 @@ export const rules = {
|
|
|
48
49
|
'reverse-comparison-in-type-checker': reverseComparisonInTypeChecker,
|
|
49
50
|
'remove-useless-path-from-type-checker': removeUselessPathFromTypeChecker,
|
|
50
51
|
'remove-useless-arrow-from-type-checker': removeUselessArrowFromTypeChecker,
|
|
52
|
+
'add-missing-arrow-to-type-checker': addMissingArrowToTypeChecker,
|
|
51
53
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-printer",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.18.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",
|