-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathexperimental-require-slot-types.ts
50 lines (49 loc) · 1.26 KB
/
experimental-require-slot-types.ts
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
import { createRule } from "../utils"
import { getLangValue } from "../utils/ast-utils"
export default createRule("experimental-require-slot-types", {
meta: {
docs: {
description:
"require slot type declaration using the `$$Slots` interface",
category: "Experimental",
recommended: false,
},
schema: [],
messages: {
missingSlotsInterface: `The component must define the $$Slots interface.`,
},
type: "suggestion",
},
create(context) {
let isTs = false
let hasSlot = false
let hasInterface = false
return {
SvelteScriptElement(node) {
const lang = getLangValue(node)?.toLowerCase()
isTs = lang === "ts" || lang === "typescript"
},
SvelteElement(node) {
if (node.name.type === "SvelteName" && node.name.name === "slot") {
hasSlot = true
}
},
TSInterfaceDeclaration(node) {
if (node.id.name === "$$Slots") {
hasInterface = true
}
},
"Program:exit"() {
if (isTs && hasSlot && !hasInterface) {
context.report({
loc: {
line: 1,
column: 1,
},
messageId: "missingSlotsInterface",
})
}
},
}
},
})