import { ParserRule } from "../types.js" import { BaseRuleVisitor } from "../utils/rule-utils.js" import { hasAttribute, getAttributeValue, findAttributeByName, getAttributes, getTagLocalName } from "@herb-tools/core" import type { UnboundLintOffense, LintContext, FullRuleConfig } from "../types.js" import type { HTMLOpenTagNode, ParseResult } from "@herb-tools/core" class NavigationHasLabelVisitor extends BaseRuleVisitor { visitHTMLOpenTagNode(node: HTMLOpenTagNode): void { this.checkNavigationElement(node) super.visitHTMLOpenTagNode(node) } private checkNavigationElement(node: HTMLOpenTagNode): void { const tagName = getTagLocalName(node) const isNavElement = tagName === "nav" const hasNavigationRole = this.hasRoleNavigation(node) if (!isNavElement && !hasNavigationRole) { return } const hasAriaLabel = hasAttribute(node, "aria-label") const hasAriaLabelledby = hasAttribute(node, "aria-labelledby") if (!hasAriaLabel && !hasAriaLabelledby) { let message = `The navigation landmark should have a unique accessible name via \`aria-label\` or \`aria-labelledby\`. Remember that the name does not need to include "navigation" or "nav" since it will already be announced.` if (hasNavigationRole && !isNavElement) { message += ` Additionally, you can safely drop the \`role="navigation"\` and replace it with the native HTML \`