-
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy path.oxlint-plugin.mjs
More file actions
55 lines (51 loc) · 1.67 KB
/
.oxlint-plugin.mjs
File metadata and controls
55 lines (51 loc) · 1.67 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
// @ts-check
// glide-plugin.js
import { definePlugin, defineRule } from "@oxlint/plugins";
const plugin = definePlugin({
meta: {
name: "glide",
},
rules: {
"require-using-for-scoped-prefs": defineRule({
meta: { type: "problem" },
// @ts-expect-error weird TS type mismatch somehow :shrug:
createOnce(context) {
return {
VariableDeclaration(node) {
switch (node.kind) {
case "using":
case "await using": {
return;
}
case "var":
case "let":
case "const": {
break;
}
}
for (const decl of node.declarations ?? []) {
if (
decl.init?.type === "CallExpression" && (
(decl.init.callee.type === "Identifier" && decl.init.callee.name === "scoped")
|| (decl.init.callee.type === "MemberExpression"
&& decl.init.callee.property.type === "Identifier"
&& decl.init.callee.property.name === "scoped"
&& decl.init.callee.object.type === "MemberExpression"
&& decl.init.callee.object.property.type === "Identifier"
&& decl.init.callee.object.property.name === "prefs")
)
) {
context.report({
node: decl,
message:
"Use `using prefs = glide.prefs.scoped()` instead of `const/let/var prefs = glide.prefs.scoped()`.",
});
}
}
},
};
},
}),
},
});
export default plugin;