-
-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathhtml-boolean-attributes-no-value.ts
More file actions
28 lines (23 loc) · 1.09 KB
/
html-boolean-attributes-no-value.ts
File metadata and controls
28 lines (23 loc) · 1.09 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
import { AttributeVisitorMixin, isBooleanAttribute, hasAttributeValue } from "./utils/rule-utils.js"
import { ParserRule } from "../types.js"
import type { LintOffense, LintContext } from "../types.js"
import type { HTMLAttributeNode, Node } from "@herb-tools/core"
class BooleanAttributesNoValueVisitor extends AttributeVisitorMixin {
protected checkAttribute(attributeName: string, _attributeValue: string | null, attributeNode: HTMLAttributeNode): void {
if (!isBooleanAttribute(attributeName)) return
if (!hasAttributeValue(attributeNode)) return
this.addOffense(
`Boolean attribute \`${attributeName}\` should not have a value. Use \`${attributeName}\` instead of \`${attributeName}="${attributeName}"\`.`,
attributeNode.value!.location,
"error"
)
}
}
export class HTMLBooleanAttributesNoValueRule extends ParserRule {
name = "html-boolean-attributes-no-value"
check(node: Node, context?: Partial<LintContext>): LintOffense[] {
const visitor = new BooleanAttributesNoValueVisitor(this.name, context)
visitor.visit(node)
return visitor.offenses
}
}