-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequired-type-arguments.js
59 lines (58 loc) · 1.28 KB
/
required-type-arguments.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
module.exports = {
meta: {
type: "problem",
docs: {
description:
"Require certain functions pass in specific number of type arguments",
},
fixable: "code",
schema: [
{
type: "array",
minItems: 0,
items: [
{
type: "array",
minItems: 2,
maxItems: 2,
items: [
{
type: "string",
},
{
type: "number",
minimum: 0,
},
],
},
],
},
],
},
create(context) {
const args = context.options;
const typeArgumentMap = args[0].reduce((acc, [fn, argCount]) => {
return {
...acc,
[fn]: argCount,
};
}, {});
return {
CallExpression(node) {
for (let fnName in typeArgumentMap) {
if (node.callee.name !== fnName) continue;
if (
!node.typeParameters ||
node.typeParameters.params.length < typeArgumentMap[fnName]
) {
context.report(
node,
`${fnName} should have at least ${typeArgumentMap[fnName]} explicit type argument(s)`
);
break;
}
}
},
};
},
};