@putout/plugin-printer 8.24.0 → 9.0.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 +11 -426
- package/lib/apply-computed-print/index.js +11 -0
- package/lib/index.js +0 -32
- package/package.json +1 -1
- package/lib/add-missing-arrow-to-type-checker/index.js +0 -77
- package/lib/add-missing-colon-to-type-checker/index.js +0 -65
- package/lib/add-missing-spaces-to-type-checker/index.js +0 -93
- package/lib/add-missing-tuples-to-type-checker/index.js +0 -94
- package/lib/apply-boolean-operator-to-type-checker/index.js +0 -60
- package/lib/check-if-success-possible-in-type-checker/index.js +0 -51
- package/lib/check-type-passed-to-type-checker/index.js +0 -97
- package/lib/merge-tuples-of-type-checkers/index.js +0 -96
- package/lib/remove-trailing-spaces-from-type-checker/index.js +0 -35
- package/lib/remove-useless-arrow-from-type-checker/index.js +0 -71
- package/lib/remove-useless-colon-from-type-checker/index.js +0 -65
- package/lib/remove-useless-not-from-type-checker/index.js +0 -79
- package/lib/remove-useless-path-from-type-checker/index.js +0 -70
- package/lib/remove-useless-spaces-from-type-checker/index.js +0 -78
- package/lib/remove-useless-tuples-from-type-checker/index.js +0 -67
- package/lib/reverse-comparison-in-type-checker/index.js +0 -32
- package/lib/types.js +0 -22
|
@@ -1,65 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
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 = addSpaces(value, where);
|
|
13
|
-
|
|
14
|
-
return `Add missing spaces: '${value}' -> '${withSpaces}'`;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const fix = ({path, where}) => {
|
|
18
|
-
const {value} = path.node;
|
|
19
|
-
setLiteralValue(path, addSpaces(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
|
-
const includes = value.includes.bind(value);
|
|
45
|
-
const endsWith = value.endsWith.bind(value);
|
|
46
|
-
const push = where.push.bind(where);
|
|
47
|
-
|
|
48
|
-
const tools = {
|
|
49
|
-
push,
|
|
50
|
-
includes,
|
|
51
|
-
endsWith,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
if (includes('->'))
|
|
55
|
-
traceArrow(tools);
|
|
56
|
-
|
|
57
|
-
if (includes(':'))
|
|
58
|
-
traceColon(tools);
|
|
59
|
-
|
|
60
|
-
return where;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function traceColon({push, includes, endsWith}) {
|
|
64
|
-
if (endsWith(':'))
|
|
65
|
-
return;
|
|
66
|
-
|
|
67
|
-
if (includes(': '))
|
|
68
|
-
return;
|
|
69
|
-
|
|
70
|
-
if (!includes(':->'))
|
|
71
|
-
push('after-colon');
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function traceArrow({includes, endsWith, push}) {
|
|
75
|
-
if (!includes(' ->'))
|
|
76
|
-
push('before-arrow');
|
|
77
|
-
|
|
78
|
-
if (!includes('-> ') && !endsWith('->'))
|
|
79
|
-
push('after-arrow');
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function addSpaces(value, where) {
|
|
83
|
-
if (where.includes('before-arrow'))
|
|
84
|
-
value = value.replace('->', ' ->');
|
|
85
|
-
|
|
86
|
-
if (where.includes('after-arrow'))
|
|
87
|
-
value = value.replace('->', '-> ');
|
|
88
|
-
|
|
89
|
-
if (where.includes('after-colon'))
|
|
90
|
-
value = value.replace(':', ': ');
|
|
91
|
-
|
|
92
|
-
return value;
|
|
93
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import {operator, types} from 'putout';
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
isArrayExpression,
|
|
5
|
-
isIdentifier,
|
|
6
|
-
isCallExpression,
|
|
7
|
-
isStringLiteral,
|
|
8
|
-
arrayExpression,
|
|
9
|
-
stringLiteral,
|
|
10
|
-
} = types;
|
|
11
|
-
|
|
12
|
-
const {
|
|
13
|
-
replaceWith,
|
|
14
|
-
createTypeChecker,
|
|
15
|
-
} = operator;
|
|
16
|
-
|
|
17
|
-
const hasResult = (value) => /^[+-]/.test(value);
|
|
18
|
-
|
|
19
|
-
const isDsl = createTypeChecker([
|
|
20
|
-
['-: -> !StringLiteral'],
|
|
21
|
-
['+: node.value ->', hasResult],
|
|
22
|
-
]);
|
|
23
|
-
|
|
24
|
-
const isSimple = createTypeChecker([
|
|
25
|
-
['+: -> Identifier'],
|
|
26
|
-
['+: -> CallExpression'],
|
|
27
|
-
['-: -> !StringLiteral'],
|
|
28
|
-
['+: node.value -> !', hasResult],
|
|
29
|
-
]);
|
|
30
|
-
|
|
31
|
-
export const report = (path) => {
|
|
32
|
-
return `Add missing tuple around: ${path}`;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export const fix = (path) => {
|
|
36
|
-
const {node} = path;
|
|
37
|
-
|
|
38
|
-
if (isIdentifier(path) || isCallExpression(path)) {
|
|
39
|
-
replaceWith(path, arrayExpression([
|
|
40
|
-
stringLiteral('+'),
|
|
41
|
-
node,
|
|
42
|
-
]));
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const {value} = node;
|
|
47
|
-
|
|
48
|
-
if (isStringLiteral(path) && !/^[+-]/.test(value)) {
|
|
49
|
-
replaceWith(path, arrayExpression([
|
|
50
|
-
stringLiteral(`+: -> ${value}`),
|
|
51
|
-
]));
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
replaceWith(path, arrayExpression([node]));
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export const traverse = ({push}) => ({
|
|
59
|
-
ArrayExpression(path) {
|
|
60
|
-
const {parentPath} = path;
|
|
61
|
-
|
|
62
|
-
if (!isCallExpression(parentPath))
|
|
63
|
-
return;
|
|
64
|
-
|
|
65
|
-
if (!isIdentifier(parentPath.node.callee, {name: 'createTypeChecker'}))
|
|
66
|
-
return;
|
|
67
|
-
|
|
68
|
-
const elements = path.get('elements');
|
|
69
|
-
|
|
70
|
-
if (isConsistent(elements))
|
|
71
|
-
return;
|
|
72
|
-
|
|
73
|
-
for (const element of elements) {
|
|
74
|
-
if (!isArrayExpression(element))
|
|
75
|
-
push(element);
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
function isConsistent(elements) {
|
|
81
|
-
const arraysCount = elements.filter(isArrayExpression).length;
|
|
82
|
-
|
|
83
|
-
if (elements.length === arraysCount)
|
|
84
|
-
return true;
|
|
85
|
-
|
|
86
|
-
const simplesCount = elements.filter(isSimple).length;
|
|
87
|
-
|
|
88
|
-
if (elements.length === simplesCount)
|
|
89
|
-
return true;
|
|
90
|
-
|
|
91
|
-
const dslCount = elements.filter(isDsl).length;
|
|
92
|
-
|
|
93
|
-
return elements.length === dslCount;
|
|
94
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import {operator, types} from 'putout';
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
compare,
|
|
5
|
-
setLiteralValue,
|
|
6
|
-
} = operator;
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
isArrayExpression,
|
|
10
|
-
isIdentifier,
|
|
11
|
-
isCallExpression,
|
|
12
|
-
} = types;
|
|
13
|
-
|
|
14
|
-
export const report = ({operator}) => `Apply boolean operator: '${operator}'`;
|
|
15
|
-
|
|
16
|
-
export const fix = ({path, operator}) => {
|
|
17
|
-
const [first] = path.node.elements;
|
|
18
|
-
const {value} = first;
|
|
19
|
-
|
|
20
|
-
setLiteralValue(first, `${value} -> ${operator}`);
|
|
21
|
-
path.node.elements.pop();
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const traverse = ({push}) => ({
|
|
25
|
-
ArrayExpression(path) {
|
|
26
|
-
const {parentPath} = path;
|
|
27
|
-
|
|
28
|
-
if (!isCallExpression(parentPath))
|
|
29
|
-
return;
|
|
30
|
-
|
|
31
|
-
const {callee} = parentPath.node;
|
|
32
|
-
|
|
33
|
-
if (!isIdentifier(callee, {name: 'createTypeChecker'}))
|
|
34
|
-
return;
|
|
35
|
-
|
|
36
|
-
const elements = path.get('elements');
|
|
37
|
-
|
|
38
|
-
for (const element of elements) {
|
|
39
|
-
if (!isArrayExpression(element))
|
|
40
|
-
continue;
|
|
41
|
-
|
|
42
|
-
const [, checker] = element.get('elements');
|
|
43
|
-
|
|
44
|
-
if (!checker)
|
|
45
|
-
return;
|
|
46
|
-
|
|
47
|
-
if (isIdentifier(checker.node, {name: 'Boolean'}))
|
|
48
|
-
push({
|
|
49
|
-
operator: '+',
|
|
50
|
-
path: element,
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
if (compare(checker.node, 'not(Boolean)'))
|
|
54
|
-
push({
|
|
55
|
-
operator: '-',
|
|
56
|
-
path: element,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
});
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import {types} from 'putout';
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
isArrayExpression,
|
|
5
|
-
isStringLiteral,
|
|
6
|
-
isIdentifier,
|
|
7
|
-
isCallExpression,
|
|
8
|
-
} = types;
|
|
9
|
-
|
|
10
|
-
export const report = () => `Success path ('+') is absent in Type Checker, all branches routes to fail ('-')`;
|
|
11
|
-
|
|
12
|
-
export const fix = () => {};
|
|
13
|
-
|
|
14
|
-
export const traverse = ({push}) => ({
|
|
15
|
-
ArrayExpression(path) {
|
|
16
|
-
const {parentPath} = path;
|
|
17
|
-
|
|
18
|
-
if (!isCallExpression(parentPath))
|
|
19
|
-
return;
|
|
20
|
-
|
|
21
|
-
const {callee} = parentPath.node;
|
|
22
|
-
|
|
23
|
-
if (!isIdentifier(callee, {name: 'createTypeChecker'}))
|
|
24
|
-
return;
|
|
25
|
-
|
|
26
|
-
const {elements} = path.node;
|
|
27
|
-
const results = elements.map(getResult);
|
|
28
|
-
const successes = results.filter(Boolean);
|
|
29
|
-
|
|
30
|
-
if (!successes.length)
|
|
31
|
-
push(path);
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const getResult = (a) => {
|
|
36
|
-
if (isStringLiteral(a)) {
|
|
37
|
-
const {value} = a;
|
|
38
|
-
|
|
39
|
-
if (value.startsWith('-'))
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (isArrayExpression(a)) {
|
|
44
|
-
const {value} = a.elements[0];
|
|
45
|
-
|
|
46
|
-
if (value.startsWith('-'))
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return true;
|
|
51
|
-
};
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import {types, operator} from 'putout';
|
|
2
|
-
import {isTypeExists} from '#types';
|
|
3
|
-
|
|
4
|
-
const {createTypeChecker} = operator;
|
|
5
|
-
const addQuotes = (a) => `'${a}'`;
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
isIdentifier,
|
|
9
|
-
isCallExpression,
|
|
10
|
-
} = types;
|
|
11
|
-
|
|
12
|
-
const ARROW = ' -> ';
|
|
13
|
-
const ARROW_NOT = ' -> !';
|
|
14
|
-
const ARROW_LENGTH = ARROW.length;
|
|
15
|
-
const ARROW_NOT_LENGTH = ARROW_NOT.length;
|
|
16
|
-
const NOT = '!';
|
|
17
|
-
|
|
18
|
-
const INSTEAD = new Map([
|
|
19
|
-
['ExportDeclaration', [
|
|
20
|
-
'ExportAllDeclaration',
|
|
21
|
-
'ExportDefaultDeclaration',
|
|
22
|
-
'ExportNamedDeclaration',
|
|
23
|
-
]],
|
|
24
|
-
]);
|
|
25
|
-
|
|
26
|
-
export const report = ({type}) => {
|
|
27
|
-
if (!INSTEAD.has(type))
|
|
28
|
-
return `Unknown type detected: '${type}'`;
|
|
29
|
-
|
|
30
|
-
const instead = INSTEAD.get(type).map(addQuotes)
|
|
31
|
-
.join(', ');
|
|
32
|
-
|
|
33
|
-
return `Unknown type detected: '${type}'. Use ${instead} instead`;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const isWrongTuple = createTypeChecker([
|
|
37
|
-
['-: parentPath.parentPath -> !ArrayExpression'],
|
|
38
|
-
['+: parentPath.node.elements.length', '=', 3],
|
|
39
|
-
]);
|
|
40
|
-
|
|
41
|
-
export const fix = () => {};
|
|
42
|
-
|
|
43
|
-
export const traverse = ({push}) => ({
|
|
44
|
-
StringLiteral(path) {
|
|
45
|
-
const call = path.find(isCallExpression);
|
|
46
|
-
|
|
47
|
-
if (!call)
|
|
48
|
-
return;
|
|
49
|
-
|
|
50
|
-
if (!isIdentifier(call.node.callee, {name: 'createTypeChecker'}))
|
|
51
|
-
return;
|
|
52
|
-
|
|
53
|
-
const {value} = path.node;
|
|
54
|
-
|
|
55
|
-
if (isWrongTuple(path))
|
|
56
|
-
return;
|
|
57
|
-
|
|
58
|
-
if (!value.includes(ARROW)) {
|
|
59
|
-
if (/^[a-zA-Z].+/.test(value) && !isTypeExists(value))
|
|
60
|
-
push({
|
|
61
|
-
path,
|
|
62
|
-
type: value,
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (value.includes(NOT)) {
|
|
69
|
-
const arrowNotIndex = value.indexOf(ARROW_NOT);
|
|
70
|
-
const typeNotIndex = arrowNotIndex + ARROW_NOT_LENGTH;
|
|
71
|
-
|
|
72
|
-
const type = value.slice(typeNotIndex, value.length);
|
|
73
|
-
|
|
74
|
-
if (!type)
|
|
75
|
-
return;
|
|
76
|
-
|
|
77
|
-
if (!isTypeExists(type))
|
|
78
|
-
push({
|
|
79
|
-
path,
|
|
80
|
-
type,
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const arrowIndex = value.indexOf(ARROW);
|
|
87
|
-
const typeIndex = arrowIndex + ARROW_LENGTH;
|
|
88
|
-
|
|
89
|
-
const type = value.slice(typeIndex, value.length);
|
|
90
|
-
|
|
91
|
-
if (!isTypeExists(type))
|
|
92
|
-
push({
|
|
93
|
-
path,
|
|
94
|
-
type,
|
|
95
|
-
});
|
|
96
|
-
},
|
|
97
|
-
});
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import {types, operator} from 'putout';
|
|
2
|
-
import {isTypeExists} from '#types';
|
|
3
|
-
|
|
4
|
-
const {
|
|
5
|
-
isArrayExpression,
|
|
6
|
-
isIdentifier,
|
|
7
|
-
isCallExpression,
|
|
8
|
-
} = types;
|
|
9
|
-
|
|
10
|
-
const {setLiteralValue} = operator;
|
|
11
|
-
const cutIS = (a) => a.slice(2);
|
|
12
|
-
|
|
13
|
-
const prepareValue = (a) => {
|
|
14
|
-
if (/^[+-]$/.test(a))
|
|
15
|
-
return `${a}: `;
|
|
16
|
-
|
|
17
|
-
if (a.endsWith('!'))
|
|
18
|
-
return a;
|
|
19
|
-
|
|
20
|
-
if (!a.endsWith('->'))
|
|
21
|
-
return `${a} -> `;
|
|
22
|
-
|
|
23
|
-
return `${a} `;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export const report = () => `Merge tuple of type checker`;
|
|
27
|
-
|
|
28
|
-
function prepareChecker(name, value) {
|
|
29
|
-
if (name === 'Boolean') {
|
|
30
|
-
if (value.endsWith('!'))
|
|
31
|
-
return `${value.slice(0, -1)}-`;
|
|
32
|
-
|
|
33
|
-
if (value.endsWith('->'))
|
|
34
|
-
return `${value} +`;
|
|
35
|
-
|
|
36
|
-
return `${value} -> +`;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return `${prepareValue(value)}${name}`;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export const fix = ({path, name}) => {
|
|
43
|
-
const [first] = path.node.elements;
|
|
44
|
-
const {value} = first;
|
|
45
|
-
|
|
46
|
-
setLiteralValue(first, prepareChecker(name, value));
|
|
47
|
-
path.node.elements.pop();
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export const traverse = ({push}) => ({
|
|
51
|
-
ArrayExpression(path) {
|
|
52
|
-
const {parentPath} = path;
|
|
53
|
-
|
|
54
|
-
if (!isCallExpression(parentPath))
|
|
55
|
-
return;
|
|
56
|
-
|
|
57
|
-
const {callee} = parentPath.node;
|
|
58
|
-
|
|
59
|
-
if (!isIdentifier(callee, {name: 'createTypeChecker'}))
|
|
60
|
-
return;
|
|
61
|
-
|
|
62
|
-
const elements = path.get('elements');
|
|
63
|
-
|
|
64
|
-
for (const element of elements) {
|
|
65
|
-
if (!isArrayExpression(element))
|
|
66
|
-
continue;
|
|
67
|
-
|
|
68
|
-
const [, checker] = element.get('elements');
|
|
69
|
-
|
|
70
|
-
if (!isIdentifier(checker))
|
|
71
|
-
continue;
|
|
72
|
-
|
|
73
|
-
const checkerName = checker.node.name;
|
|
74
|
-
|
|
75
|
-
if (checkerName === 'Boolean')
|
|
76
|
-
push({
|
|
77
|
-
path: element,
|
|
78
|
-
name: 'Boolean',
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
if (!checkerName.startsWith('is'))
|
|
82
|
-
continue;
|
|
83
|
-
|
|
84
|
-
const name = cutIS(checkerName);
|
|
85
|
-
|
|
86
|
-
if (!name)
|
|
87
|
-
continue;
|
|
88
|
-
|
|
89
|
-
if (isTypeExists(name))
|
|
90
|
-
push({
|
|
91
|
-
path: element,
|
|
92
|
-
name,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
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) => {
|
|
11
|
-
const {value} = path.node;
|
|
12
|
-
const trimmed = value.trim();
|
|
13
|
-
|
|
14
|
-
return `Avoid trailing spaces: '${value}' -> '${trimmed}'`;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const fix = (path) => {
|
|
18
|
-
setLiteralValue(path, path.node.value.trim());
|
|
19
|
-
};
|
|
20
|
-
export const traverse = ({push}) => ({
|
|
21
|
-
StringLiteral(path) {
|
|
22
|
-
const call = path.find(isCallExpression);
|
|
23
|
-
|
|
24
|
-
if (!call)
|
|
25
|
-
return;
|
|
26
|
-
|
|
27
|
-
if (!isIdentifier(call.node.callee, {name: 'createTypeChecker'}))
|
|
28
|
-
return;
|
|
29
|
-
|
|
30
|
-
const {value} = path.node;
|
|
31
|
-
|
|
32
|
-
if (value.endsWith(' '))
|
|
33
|
-
push(path);
|
|
34
|
-
},
|
|
35
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import {operator, types} from 'putout';
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
isIdentifier,
|
|
5
|
-
isCallExpression,
|
|
6
|
-
isArrayExpression,
|
|
7
|
-
} = types;
|
|
8
|
-
|
|
9
|
-
const {setLiteralValue} = operator;
|
|
10
|
-
|
|
11
|
-
export const report = ({path, where}) => {
|
|
12
|
-
const {value} = path.node;
|
|
13
|
-
const withSpaces = removeArrow(value, where);
|
|
14
|
-
|
|
15
|
-
return `Remove useless arrow: '${value}' -> '${withSpaces}'`;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const fix = ({path, where}) => {
|
|
19
|
-
const {value} = path.node;
|
|
20
|
-
setLiteralValue(path, removeArrow(value, where));
|
|
21
|
-
};
|
|
22
|
-
export const traverse = ({push}) => ({
|
|
23
|
-
StringLiteral(path) {
|
|
24
|
-
const call = path.find(isCallExpression);
|
|
25
|
-
|
|
26
|
-
if (!call)
|
|
27
|
-
return;
|
|
28
|
-
|
|
29
|
-
if (!isIdentifier(call.node.callee, {name: 'createTypeChecker'}))
|
|
30
|
-
return;
|
|
31
|
-
|
|
32
|
-
const where = createWhere(path);
|
|
33
|
-
|
|
34
|
-
if (where.length)
|
|
35
|
-
push({
|
|
36
|
-
path,
|
|
37
|
-
where,
|
|
38
|
-
});
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
function createWhere(path) {
|
|
43
|
-
const {value} = path.node;
|
|
44
|
-
const where = [];
|
|
45
|
-
const hasNot = value.includes('!');
|
|
46
|
-
|
|
47
|
-
if (value.includes('-> ->'))
|
|
48
|
-
where.push('duplicate');
|
|
49
|
-
|
|
50
|
-
if (!hasNot && isInsideCompareTuple(path) && value.includes(' -> '))
|
|
51
|
-
where.push('useless');
|
|
52
|
-
|
|
53
|
-
return where;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function removeArrow(value, where) {
|
|
57
|
-
if (where.includes('duplicate'))
|
|
58
|
-
value = value.replace('-> ->', '->');
|
|
59
|
-
|
|
60
|
-
if (where.includes('useless'))
|
|
61
|
-
value = value.replace(' -> ', '');
|
|
62
|
-
|
|
63
|
-
return value;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function isInsideCompareTuple({parentPath}) {
|
|
67
|
-
if (!isArrayExpression(parentPath.parentPath))
|
|
68
|
-
return false;
|
|
69
|
-
|
|
70
|
-
return parentPath.node.elements.length === 3;
|
|
71
|
-
}
|