-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathexperimental-require-strict-events.ts
45 lines (44 loc) · 1.25 KB
/
experimental-require-strict-events.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
import { createRule } from "../utils"
import { findAttribute, getLangValue } from "../utils/ast-utils"
export default createRule("experimental-require-strict-events", {
meta: {
docs: {
description: "require the strictEvents attribute on <script> tags",
category: "Experimental",
recommended: false,
},
schema: [],
messages: {
missingStrictEvents: `The component must have the strictEvents attribute on its <script> tag or it must define the $$Events interface.`,
},
type: "suggestion",
},
create(context) {
let isTs = false
let hasAttribute = false
let hasInterface = false
return {
SvelteScriptElement(node) {
const lang = getLangValue(node)?.toLowerCase()
isTs = lang === "ts" || lang === "typescript"
hasAttribute = findAttribute(node, "strictEvents") !== null
},
TSInterfaceDeclaration(node) {
if (node.id.name === "$$Events") {
hasInterface = true
}
},
"Program:exit"() {
if (isTs && !hasAttribute && !hasInterface) {
context.report({
loc: {
line: 1,
column: 1,
},
messageId: "missingStrictEvents",
})
}
},
}
},
})