-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlint-plugin.ts
More file actions
80 lines (80 loc) · 2.95 KB
/
lint-plugin.ts
File metadata and controls
80 lines (80 loc) · 2.95 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
export default {
name: "lint-plugin",
rules: {
"rule": {
create(context) {
return {
ExportAllDeclaration(node) {
//done: exported and source are swapped
const source = node.source;
const exported = node.exported;
if (exported?.type === "Identifier") {
context.report({
node,
message:
`Exported \`${exported.name}\` and source \`${source.value}\` are swapped`,
});
}
},
"ClassBody > PropertyDefinition"(node) {
//done: parent child relation is not working, maybe it should be "ClassBody.body > PropertyDefinition"?
if (node.key.type === "Identifier") {
context.report({ node, message: "this should fire!" });
}
},
PropertyDefinition(node) {
if (node.key.type === "PrivateIdentifier") {
//done: PrivateIdentifier is missing from the type definition
context.report({ node, message: node.key.type });
}
},
ObjectPattern(node) {
for (const prop of node.properties) {
switch (prop.type) {
case "Property": {
const key = prop.key;
const value = prop.value;
if (value === null) { //todo: value can be null
context.report({ node, message: "value null" });
} else {
switch (value.type) {
case "Identifier":
//done: see test: "ObjectPattern Property value should be key"
if (
JSON.stringify(key.range) ===
JSON.stringify(value.range)
) {
context.report({
node,
message: "value is same as key",
});
}
break;
case "AssignmentPattern":
if (value.left.type === "Identifier") {
context.report({
node,
message: "AssignmentPattern",
});
}
break;
case "Literal":
//done: should be assignment pattern, see test "ObjectPattern Property value assignment"
if (key.type === "Identifier") {
context.report({
node,
message: "not AssignmentPattern",
});
}
break;
}
}
}
}
}
},
};
},
},
},
} satisfies Deno.lint.Plugin;