Skip to content

Commit

Permalink
feat(require-strict-events): reporting lint issue on script tag
Browse files Browse the repository at this point in the history
  • Loading branch information
marekdedic committed Feb 9, 2023
1 parent 67486eb commit 99477b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/rules/experimental-require-strict-events.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { AST } from "svelte-eslint-parser"

import { createRule } from "../utils"
import { findAttribute, getLangValue } from "../utils/ast-utils"

Expand All @@ -18,11 +20,13 @@ export default createRule("experimental-require-strict-events", {
let isTs = false
let hasAttribute = false
let hasInterface = false
let scriptNode: AST.SvelteScriptElement
return {
SvelteScriptElement(node) {
const lang = getLangValue(node)?.toLowerCase()
isTs = lang === "ts" || lang === "typescript"
hasAttribute = findAttribute(node, "strictEvents") !== null
scriptNode = node
},
TSInterfaceDeclaration(node) {
if (node.id.name === "$$Events") {
Expand All @@ -32,10 +36,7 @@ export default createRule("experimental-require-strict-events", {
"Program:exit"() {
if (isTs && !hasAttribute && !hasInterface) {
context.report({
loc: {
line: 1,
column: 1,
},
node: scriptNode,
messageId: "missingStrictEvents",
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
The component must have the strictEvents attribute on its <script> tag
or it must define the $$Events interface.
line: 1
column: 2
column: 1
suggestions: null

0 comments on commit 99477b9

Please sign in to comment.