-
-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathhtml-aria-role-must-be-valid.ts
More file actions
31 lines (24 loc) · 1.01 KB
/
html-aria-role-must-be-valid.ts
File metadata and controls
31 lines (24 loc) · 1.01 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
import { AttributeVisitorMixin, VALID_ARIA_ROLES } from "./utils/rule-utils.js"
import { ParserRule } from "../types.js"
import type { LintOffense, LintContext } from "../types.js"
import type { Node, HTMLAttributeNode } from "@herb-tools/core"
class AriaRoleMustBeValid extends AttributeVisitorMixin {
checkAttribute(attributeName: string, attributeValue: string | null, attributeNode: HTMLAttributeNode,): void {
if (attributeName !== "role") return
if (attributeValue === null) return
if (VALID_ARIA_ROLES.has(attributeValue)) return
this.addOffense(
`The \`role\` attribute must be a valid ARIA role. Role \`${attributeValue}\` is not recognized.`,
attributeNode.location,
"error"
)
}
}
export class HTMLAriaRoleMustBeValidRule extends ParserRule {
name = "html-aria-role-must-be-valid"
check(node: Node, context?: Partial<LintContext>): LintOffense[] {
const visitor = new AriaRoleMustBeValid(this.name, context)
visitor.visit(node)
return visitor.offenses
}
}