Documentation
¶
Index ¶
- Constants
- Variables
- func AncestorWithTag(n *parser.Node, tag string) *parser.Node
- func ChildElements(n *parser.Node) []*parser.Node
- func CountChildrenWithTag(n *parser.Node, tag string) int
- func FindDescendant(n *parser.Node, pred func(*parser.Node) bool) *parser.Node
- func FirstChildElement(n *parser.Node) *parser.Node
- func GetAccessibleName(n *parser.Node) string
- func GetImplicitRole(tagName string, n *parser.Node) string
- func HasAccessibleName(n *parser.Node) bool
- func HasAncestor(n *parser.Node, tags ...string) bool
- func HasChildWithTag(n *parser.Node, tag string) bool
- func HasDescendant(n *parser.Node, pred func(*parser.Node) bool) bool
- func HasUTF8BOM(content []byte) bool
- func HeadingRank(tagName string) int
- func IsCustomElement(tagName string) bool
- func IsElementNode(n *parser.Node) bool
- func IsHTMXAttribute(name string) bool
- func IsTemplateExpr(s string) bool
- func NormalizeText(s string) string
- func Tag(n *parser.Node) string
- func TagEquals(n *parser.Node, tag string) bool
- func TagIn(n *parser.Node, tags ...string) bool
- func ValidateHTMXAttribute(name, version string) (valid, deprecated, v4Only bool)
- type AllowedLinks
- type AreaAlt
- type AriaHiddenBody
- type AriaLabelMisuse
- type AttrSpec
- type AttrType
- type AttributeAllowedValues
- type AttributeMisuse
- type ButtonName
- type ButtonType
- type ClassPattern
- type ContentModel
- type Deprecated
- type DoctypeHTML
- type DuplicateID
- type ElementName
- type ElementPermittedContent
- type ElementPermittedOccurrences
- type ElementPermittedOrder
- type ElementPermittedParent
- type ElementRequiredAncestor
- type ElementRequiredAttributes
- type ElementRequiredContent
- type ElementSpec
- type EmptyTitle
- type FormDupName
- type FormSubmit
- type HTMXAttributes
- type HTMXConfigurable
- type HeadingContent
- type HeadingLevel
- type HiddenFocusable
- type IDPattern
- type ImgAlt
- type InputAttributes
- type InputAttributesConfig
- type InputLabel
- type LinkName
- type LongTitle
- type MapDupName
- type MapIDName
- type MetaRefresh
- type MissingDoctype
- type MultipleLabeledControls
- type NamePattern
- type NoAbstractRole
- type NoAutoplay
- type NoConditionalComment
- type NoDeprecatedAttr
- type NoDupAttr
- type NoDupClass
- type NoImplicitInputType
- type NoInlineStyle
- type NoMissingReferences
- type NoMultipleMain
- type NoRedundantFor
- type NoRedundantRole
- type NoStyleTag
- type NoUTF8BOM
- type PreferAria
- type PreferButton
- type PreferNativeElement
- type PreferSemantic
- type PreferTbody
- type RawRule
- type RedundantAriaLabel
- type Registry
- type RequireCSPNonce
- type RequireLang
- type RequireSRI
- type Result
- type Rule
- type SVGFocusable
- type ScriptElement
- type ScriptType
- type Severity
- type TabindexNoPositive
- type TelNonBreaking
- type TemplateSyntaxValid
- type TemplateWhitespaceTrim
- type TextContent
- type UniqueLandmark
- type ValidAutocomplete
- type ValidID
- type VoidContent
- type WcagH36
- type WcagH63
- type WcagH67
- type WcagH71
Constants ¶
const ( RuleDoctypeHTML = "doctype-html" RuleMissingDoctype = "missing-doctype" )
Rule name constants for doctype rules.
const ( RuleImgAlt = "img-alt" RuleAreaAlt = "area-alt" RuleInputLabel = "input-label" RuleButtonName = "button-name" RuleLinkName = "link-name" RuleHeadingContent = "heading-content" RuleHeadingLevel = "heading-level" RuleTextContent = "text-content" RuleEmptyTitle = "empty-title" RuleLongTitle = "long-title" RulePreferAria = "prefer-aria" RuleAriaHiddenBody = "aria-hidden-body" RuleHiddenFocusable = "hidden-focusable" RuleRedundantAriaLabel = "no-redundant-aria-label" RuleNoRedundantRole = "no-redundant-role" RuleNoAbstractRole = "no-abstract-role" RuleAriaLabelMisuse = "aria-label-misuse" RuleUniqueLandmark = "unique-landmark" RuleFormSubmit = "form-submit" RuleButtonType = "button-type" RuleMultipleLabeledControls = "multiple-labeled-controls" RuleFormDupName = "form-dup-name" RuleNoRedundantFor = "no-redundant-for" RuleValidAutocomplete = "valid-autocomplete" RuleNoImplicitInputType = "no-implicit-input-type" RuleInputAttributes = "input-attributes" RuleTabindexNoPositive = "tabindex-no-positive" RuleSVGFocusable = "svg-focusable" RuleNoAutoplay = "no-autoplay" RuleMetaRefresh = "meta-refresh" RuleWcagH36 = "wcag/h36" RuleWcagH63 = "wcag/h63" RuleWcagH67 = "wcag/h67" RuleWcagH71 = "wcag/h71" RulePreferSemantic = "prefer-semantic" RuleDuplicateID = "duplicate-id" RulePreferButton = "prefer-button" RuleNoInlineStyle = "no-inline-style" RulePreferNativeElement = "prefer-native-element" RulePreferTbody = "prefer-tbody" RuleNoDupAttr = "no-dup-attr" RuleNoDupClass = "no-dup-class" RuleMapIDName = "map-id-name" RuleMapDupName = "map-dup-name" RuleElementName = "element-name" RuleScriptType = "script-type" RuleScriptElement = "script-element" RuleAttributeAllowedValues = "attribute-allowed-values" RuleAttributeMisuse = "attribute-misuse" RuleDeprecated = "deprecated" RuleNoDeprecatedAttr = "no-deprecated-attr" RuleNoConditionalComment = "no-conditional-comment" RuleVoidContent = "void-content" RuleElementRequiredAncestor = "element-required-ancestor" RuleElementPermittedParent = "element-permitted-parent" RuleElementRequiredAttributes = "element-required-attributes" RuleElementPermittedContent = "element-permitted-content" RuleElementPermittedOccurrences = "element-permitted-occurrences" RuleElementRequiredContent = "element-required-content" RuleElementPermittedOrder = "element-permitted-order" RuleNoMultipleMain = "no-multiple-main" RuleValidID = "valid-id" RuleRequireLang = "require-lang" RuleNoMissingReferences = "no-missing-references" RuleAllowedLinks = "allowed-links" RuleNoUTF8BOM = "no-utf8-bom" RuleTelNonBreaking = "tel-non-breaking" RuleRequireSRI = "require-sri" RuleRequireCSPNonce = "require-csp-nonce" RuleNoStyleTag = "no-style-tag" RuleClassPattern = "class-pattern" RuleIDPattern = "id-pattern" RuleNamePattern = "name-pattern" RuleHTMXAttributes = "htmx-attributes" RuleTemplateWhitespaceTrim = "template-whitespace-trim" RuleTemplateSyntaxValid = "template-syntax-valid" )
Rule name constants to avoid magic strings.
const MaxTitleLength = 70
MaxTitleLength is the recommended maximum title length for SEO.
const TemplateExprPlaceholder = "TMPL"
TemplateExprPlaceholder is the placeholder inserted for Go template expressions. The parser replaces {{.Field}} expressions with this value.
Variables ¶
var AbstractRoles = map[string]bool{ "command": true, "composite": true, "input": true, "landmark": true, "range": true, "roletype": true, "section": true, "sectionhead": true, "select": true, "structure": true, "widget": true, "window": true, }
AbstractRoles are ARIA roles that must not be used directly. See: https://www.w3.org/TR/wai-aria/#abstract_roles
var AriaLabelableElements = map[string]bool{ "main": true, "nav": true, "aside": true, "header": true, "footer": true, "section": true, "article": true, "form": true, "a": true, "button": true, "input": true, "select": true, "textarea": true, "table": true, "dialog": true, "iframe": true, "img": true, "figure": true, "summary": true, "details": true, "meter": true, "output": true, "progress": true, "svg": true, }
AriaLabelableElements are elements that can have aria-label/aria-labelledby.
var AutocompleteSectionPrefixes = []string{
"section-",
"shipping",
"billing",
}
AutocompleteSectionPrefixes are valid prefixes for autocomplete section tokens.
var AutocompleteTokens = map[string]bool{ "on": true, "off": true, "name": true, "honorific-prefix": true, "given-name": true, "additional-name": true, "family-name": true, "honorific-suffix": true, "nickname": true, "organization-title": true, "username": true, "new-password": true, "current-password": true, "one-time-code": true, "organization": true, "street-address": true, "address-line1": true, "address-line2": true, "address-line3": true, "address-level4": true, "address-level3": true, "address-level2": true, "address-level1": true, "country": true, "country-name": true, "postal-code": true, "cc-name": true, "cc-given-name": true, "cc-additional-name": true, "cc-family-name": true, "cc-number": true, "cc-exp": true, "cc-exp-month": true, "cc-exp-year": true, "cc-csc": true, "cc-type": true, "transaction-currency": true, "transaction-amount": true, "language": true, "bday": true, "bday-day": true, "bday-month": true, "bday-year": true, "sex": true, "url": true, "photo": true, "tel": true, "tel-country-code": true, "tel-national": true, "tel-area-code": true, "tel-local": true, "tel-local-prefix": true, "tel-local-suffix": true, "tel-extension": true, "email": true, "impp": true, "webauthn": true, }
AutocompleteTokens lists valid autocomplete attribute values. Per HTML spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute
var ButtonLikeInputTypes = map[string]bool{ "button": true, "submit": true, "reset": true, "image": true, }
ButtonLikeInputTypes are input types that behave like buttons.
var DeprecatedAttributes = map[string]map[string]string{
"": {
"align": "use CSS text-align or flexbox",
"bgcolor": "use CSS background-color",
"border": "use CSS border",
"cellpadding": "use CSS padding",
"cellspacing": "use CSS border-spacing",
"char": "use CSS text-align",
"charoff": "use CSS text-align",
"clear": "use CSS clear",
"compact": "use CSS",
"frame": "use CSS border",
"frameborder": "use CSS border",
"height": "use CSS height (except on img, video, canvas)",
"hspace": "use CSS margin",
"marginheight": "use CSS margin",
"marginwidth": "use CSS margin",
"noshade": "use CSS",
"nowrap": "use CSS white-space",
"rules": "use CSS border",
"scrolling": "use CSS overflow",
"size": "use CSS",
"valign": "use CSS vertical-align",
"vspace": "use CSS margin",
"width": "use CSS width (except on img, video, canvas)",
},
"a": {
"charset": "use Content-Type header",
"coords": "not supported",
"name": "use id instead",
"rev": "use rel instead",
"shape": "not supported",
},
"body": {
"alink": "use CSS :active selector",
"background": "use CSS background-image",
"bgcolor": "use CSS background-color",
"link": "use CSS :link selector",
"text": "use CSS color",
"vlink": "use CSS :visited selector",
},
"br": {
"clear": "use CSS clear",
},
"caption": {
"align": "use CSS caption-side",
},
"col": {
"align": "use CSS text-align",
"char": "use CSS text-align",
"charoff": "use CSS text-align",
"valign": "use CSS vertical-align",
"width": "use CSS width",
},
"div": {
"align": "use CSS text-align",
},
"embed": {
"align": "use CSS",
"name": "use id instead",
},
"form": {
"accept": "use accept on input elements",
},
"h1": {"align": "use CSS text-align"},
"h2": {"align": "use CSS text-align"},
"h3": {"align": "use CSS text-align"},
"h4": {"align": "use CSS text-align"},
"h5": {"align": "use CSS text-align"},
"h6": {"align": "use CSS text-align"},
"head": {
"profile": "removed from spec",
},
"hr": {
"align": "use CSS margin",
"color": "use CSS background-color",
"noshade": "use CSS",
"size": "use CSS height",
"width": "use CSS width",
},
"html": {
"manifest": "use service workers instead",
"version": "removed from spec",
},
"iframe": {
"align": "use CSS",
"frameborder": "use CSS border",
"longdesc": "use aria-describedby",
"marginheight": "use CSS margin",
"marginwidth": "use CSS margin",
"scrolling": "use CSS overflow",
},
"img": {
"align": "use CSS float or vertical-align",
"border": "use CSS border",
"hspace": "use CSS margin",
"longdesc": "use aria-describedby",
"name": "use id instead",
"vspace": "use CSS margin",
},
"input": {
"align": "use CSS",
"usemap": "not supported",
},
"legend": {
"align": "use CSS",
},
"li": {
"type": "use CSS list-style-type",
"value": "use value attribute on ol instead",
},
"link": {
"charset": "use Content-Type header",
"rev": "use rel instead",
"target": "not supported",
},
"menu": {
"compact": "use CSS",
},
"meta": {
"scheme": "removed from spec",
},
"object": {
"align": "use CSS",
"archive": "removed from spec",
"border": "use CSS border",
"classid": "removed from spec",
"code": "removed from spec",
"codebase": "removed from spec",
"codetype": "removed from spec",
"declare": "removed from spec",
"hspace": "use CSS margin",
"standby": "removed from spec",
"vspace": "use CSS margin",
},
"ol": {
"compact": "use CSS",
},
"p": {
"align": "use CSS text-align",
},
"pre": {
"width": "use CSS width",
},
"script": {
"charset": "use UTF-8",
"language": "use type instead",
},
"table": {
"align": "use CSS margin or float",
"bgcolor": "use CSS background-color",
"border": "use CSS border",
"cellpadding": "use CSS padding",
"cellspacing": "use CSS border-spacing",
"frame": "use CSS border",
"rules": "use CSS border",
"summary": "use caption or aria-describedby",
"width": "use CSS width",
},
"tbody": {
"align": "use CSS text-align",
"char": "use CSS text-align",
"charoff": "use CSS text-align",
"valign": "use CSS vertical-align",
},
"td": {
"abbr": "removed from spec for td",
"align": "use CSS text-align",
"axis": "removed from spec",
"bgcolor": "use CSS background-color",
"char": "use CSS text-align",
"charoff": "use CSS text-align",
"height": "use CSS height",
"nowrap": "use CSS white-space",
"scope": "use on th instead",
"valign": "use CSS vertical-align",
"width": "use CSS width",
},
"tfoot": {
"align": "use CSS text-align",
"char": "use CSS text-align",
"charoff": "use CSS text-align",
"valign": "use CSS vertical-align",
},
"th": {
"align": "use CSS text-align",
"axis": "removed from spec",
"bgcolor": "use CSS background-color",
"char": "use CSS text-align",
"charoff": "use CSS text-align",
"height": "use CSS height",
"nowrap": "use CSS white-space",
"valign": "use CSS vertical-align",
"width": "use CSS width",
},
"thead": {
"align": "use CSS text-align",
"char": "use CSS text-align",
"charoff": "use CSS text-align",
"valign": "use CSS vertical-align",
},
"tr": {
"align": "use CSS text-align",
"bgcolor": "use CSS background-color",
"char": "use CSS text-align",
"charoff": "use CSS text-align",
"valign": "use CSS vertical-align",
},
"ul": {
"compact": "use CSS",
"type": "use CSS list-style-type",
},
}
DeprecatedAttributes maps element names to their deprecated attributes. Empty string key "" means the attribute is globally deprecated.
var DeprecatedElements = map[string]string{
"acronym": "use <abbr> instead",
"applet": "use <object> or <embed> instead",
"basefont": "use CSS font properties instead",
"bgsound": "use <audio> instead",
"big": "use CSS font-size instead",
"blink": "use CSS animation instead",
"center": "use CSS text-align or flexbox instead",
"command": "removed from spec",
"content": "removed from spec",
"dir": "use <ul> instead",
"font": "use CSS font properties instead",
"frame": "use <iframe> or CSS instead",
"frameset": "use <iframe> or CSS instead",
"image": "use <img> instead (non-standard)",
"isindex": "use <input> instead",
"keygen": "use Web Crypto API instead",
"listing": "use <pre> or <code> instead",
"marquee": "use CSS animation instead",
"menuitem": "removed from spec",
"multicol": "use CSS columns instead",
"nextid": "removed from spec",
"nobr": "use CSS white-space instead",
"noembed": "removed from spec",
"noframes": "frames are obsolete",
"param": "use object data attribute instead",
"plaintext": "use <pre> or text/plain MIME type",
"rb": "removed from spec",
"rtc": "removed from spec",
"shadow": "removed from spec",
"spacer": "use CSS margin/padding instead",
"strike": "use <del> or <s> instead",
"tt": "use <code>, <kbd>, or <samp> instead",
"xmp": "use <pre> and escape HTML instead",
}
DeprecatedElements maps deprecated HTML elements to replacement guidance. Based on HTML5 spec and MDN documentation.
var ElementSpecs = map[string]ElementSpec{ "html": { ContentModel: ModelNone, RequiredChildren: []string{"head", "body"}, }, "head": { ContentModel: ModelMetadata, RequiredChildren: []string{"title"}, PermittedParents: []string{"html"}, }, "body": { ContentModel: ModelFlow, PermittedParents: []string{"html"}, }, "title": { ContentModel: ModelNone, PermittedParents: []string{"head"}, }, "ul": { ContentModel: ModelFlow, PermittedContent: []string{"li", "script", "template"}, }, "ol": { ContentModel: ModelFlow, PermittedContent: []string{"li", "script", "template"}, }, "li": { ContentModel: ModelFlow, RequiredParent: "ul", }, "dl": { ContentModel: ModelFlow, PermittedContent: []string{"dt", "dd", "div", "script", "template"}, }, "dt": { ContentModel: ModelFlow, RequiredParent: "dl", }, "dd": { ContentModel: ModelFlow, RequiredParent: "dl", }, "table": { ContentModel: ModelFlow, PermittedContent: []string{"caption", "colgroup", "thead", "tbody", "tfoot", "tr", "script", "template"}, }, "caption": { ContentModel: ModelFlow, PermittedParents: []string{"table"}, }, "colgroup": { ContentModel: ModelNone, PermittedContent: []string{"col", "template"}, PermittedParents: []string{"table"}, }, "col": { VoidElement: true, PermittedParents: []string{"colgroup"}, }, "thead": { ContentModel: ModelNone, PermittedContent: []string{"tr", "script", "template"}, PermittedParents: []string{"table"}, }, "tbody": { ContentModel: ModelNone, PermittedContent: []string{"tr", "script", "template"}, PermittedParents: []string{"table"}, }, "tfoot": { ContentModel: ModelNone, PermittedContent: []string{"tr", "script", "template"}, PermittedParents: []string{"table"}, }, "tr": { ContentModel: ModelNone, PermittedContent: []string{"td", "th", "script", "template"}, RequiredParent: "table", }, "td": { ContentModel: ModelFlow, PermittedParents: []string{"tr"}, }, "th": { ContentModel: ModelFlow, PermittedParents: []string{"tr"}, }, "form": { ContentModel: ModelFlow, ForbiddenContent: []string{"form"}, }, "fieldset": { ContentModel: ModelFlow, }, "legend": { ContentModel: ModelPhrasing, PermittedParents: []string{"fieldset"}, }, "label": { ContentModel: ModelPhrasing, ForbiddenContent: []string{"label"}, }, "select": { ContentModel: ModelNone, PermittedContent: []string{"option", "optgroup", "hr", "script", "template"}, }, "optgroup": { ContentModel: ModelNone, PermittedContent: []string{"option", "script", "template"}, PermittedParents: []string{"select"}, }, "option": { ContentModel: ModelNone, RequiredParent: "select", }, "datalist": { ContentModel: ModelPhrasing, PermittedContent: []string{"option", "script", "template"}, }, "picture": { ContentModel: ModelNone, PermittedContent: []string{"source", "img", "script", "template"}, }, "video": { ContentModel: ModelTransparent, PermittedContent: []string{"source", "track"}, }, "audio": { ContentModel: ModelTransparent, PermittedContent: []string{"source", "track"}, }, "source": { VoidElement: true, PermittedParents: []string{"audio", "video", "picture"}, }, "track": { VoidElement: true, PermittedParents: []string{"audio", "video"}, }, "map": { ContentModel: ModelTransparent, RequiredAttributes: []string{"name"}, }, "area": { VoidElement: true, PermittedParents: []string{"map"}, }, "details": { ContentModel: ModelFlow, }, "summary": { ContentModel: ModelPhrasing, PermittedParents: []string{"details"}, }, "ruby": { ContentModel: ModelPhrasing, PermittedContent: []string{"rt", "rp"}, }, "rt": { ContentModel: ModelPhrasing, PermittedParents: []string{"ruby"}, }, "rp": { ContentModel: ModelNone, PermittedParents: []string{"ruby"}, }, "br": {VoidElement: true}, "hr": {VoidElement: true}, "img": {VoidElement: true, RequiredAttributes: []string{"src", "alt"}}, "input": {VoidElement: true}, "meta": {VoidElement: true}, "link": {VoidElement: true}, "base": {VoidElement: true}, "embed": {VoidElement: true}, "wbr": {VoidElement: true}, "param": {VoidElement: true, Deprecated: true, DeprecatedMessage: "use object data attribute"}, }
ElementSpecs provides detailed constraints for elements that need special validation. Not all elements need entries here - only those with specific requirements.
var ForbiddenDescendants = map[string][]string{
"a": {"a"},
"button": {"a", "button", "input", "select", "textarea"},
"label": {"label"},
"form": {"form"},
"progress": {"progress"},
"meter": {"meter"},
"dfn": {"dfn"},
"abbr": {"abbr"},
"header": {"header", "footer"},
"footer": {"header", "footer"},
"address": {"address", "header", "footer"},
}
ForbiddenDescendants maps elements to descendants they cannot contain.
var FormControlElements = map[string]bool{ "input": true, "select": true, "textarea": true, "button": true, "output": true, }
FormControlElements are HTML elements that act as form controls.
var HTMLCharacterReferences = map[string]bool{ "amp": true, "lt": true, "gt": true, "quot": true, "apos": true, "nbsp": true, "copy": true, "reg": true, "trade": true, "plusmn": true, "times": true, "divide": true, "minus": true, "equals": true, "ne": true, "le": true, "ge": true, "infin": true, "sum": true, "prod": true, "radic": true, "alpha": true, "beta": true, "gamma": true, "delta": true, "epsilon": true, "zeta": true, "eta": true, "theta": true, "iota": true, "kappa": true, "lambda": true, "mu": true, "nu": true, "xi": true, "omicron": true, "pi": true, "rho": true, "sigma": true, "tau": true, "upsilon": true, "phi": true, "chi": true, "psi": true, "omega": true, "cent": true, "pound": true, "yen": true, "euro": true, "curren": true, "mdash": true, "ndash": true, "lsquo": true, "rsquo": true, "ldquo": true, "rdquo": true, "hellip": true, "bull": true, "larr": true, "rarr": true, "uarr": true, "darr": true, "harr": true, "deg": true, "para": true, "sect": true, "dagger": true, "Dagger": true, "laquo": true, "raquo": true, "iexcl": true, "iquest": true, "frac14": true, "frac12": true, "frac34": true, }
HTMLCharacterReferences lists valid named character references. This is a subset of the most common ones; the full list is very large. See: https://html.spec.whatwg.org/multipage/named-characters.html
var HTMXv2Attributes = map[string]bool{ "hx-get": true, "hx-post": true, "hx-put": true, "hx-patch": true, "hx-delete": true, "hx-swap": true, "hx-swap-oob": true, "hx-target": true, "hx-select": true, "hx-select-oob": true, "hx-trigger": true, "hx-sync": true, "hx-boost": true, "hx-push-url": true, "hx-replace-url": true, "hx-vals": true, "hx-vars": true, "hx-headers": true, "hx-params": true, "hx-include": true, "hx-encoding": true, "hx-request": true, "hx-confirm": true, "hx-prompt": true, "hx-validate": true, "hx-disable": true, "hx-disabled-elt": true, "hx-disinherit": true, "hx-inherit": true, "hx-ext": true, "hx-history": true, "hx-history-elt": true, "hx-indicator": true, "hx-preserve": true, }
HTMXv2Attributes contains all valid htmx 2.x attributes.
var HTMXv4Attributes = func() map[string]bool { attrs := make(map[string]bool) for attr := range HTMXv2Attributes { if !HTMXv4DeprecatedAttributes[attr] { attrs[attr] = true } } for attr := range HTMXv4OnlyAttributes { attrs[attr] = true } return attrs }()
HTMXv4Attributes contains all valid htmx 4.x attributes (v2 minus deprecated, plus v4-only).
var HTMXv4DeprecatedAttributes = map[string]bool{ "hx-disabled-elt": true, "hx-disinherit": true, "hx-history-elt": true, "hx-request": true, "hx-vars": true, }
HTMXv4DeprecatedAttributes contains v2 attributes deprecated/removed in v4.
var HTMXv4OnlyAttributes = map[string]bool{ "hx-action": true, "hx-config": true, "hx-ignore": true, "hx-method": true, "hx-optimistic": true, "hx-preload": true, }
HTMXv4OnlyAttributes contains attributes that are only valid in htmx 4.x.
var HeadingTags = map[string]bool{ "h1": true, "h2": true, "h3": true, "h4": true, "h5": true, "h6": true, }
HeadingTags identifies heading elements (h1-h6).
var ImplicitRoles = map[string]string{
"a": "link",
"article": "article",
"aside": "complementary",
"button": "button",
"dialog": "dialog",
"form": "form",
"h1": "heading",
"h2": "heading",
"h3": "heading",
"h4": "heading",
"h5": "heading",
"h6": "heading",
"header": "banner",
"footer": "contentinfo",
"img": "img",
"input": "",
"li": "listitem",
"main": "main",
"nav": "navigation",
"ol": "list",
"option": "option",
"progress": "progressbar",
"section": "region",
"select": "combobox",
"table": "table",
"tbody": "rowgroup",
"td": "cell",
"textarea": "textbox",
"tfoot": "rowgroup",
"th": "columnheader",
"thead": "rowgroup",
"tr": "row",
"ul": "list",
}
ImplicitRoles maps HTML elements to their implicit ARIA roles.
var InputTypeAttributes = map[string]map[string]bool{ "text": { "autocomplete": true, "dirname": true, "list": true, "maxlength": true, "minlength": true, "pattern": true, "placeholder": true, "readonly": true, "required": true, "size": true, }, "search": { "autocomplete": true, "dirname": true, "list": true, "maxlength": true, "minlength": true, "pattern": true, "placeholder": true, "readonly": true, "required": true, "size": true, }, "url": { "autocomplete": true, "list": true, "maxlength": true, "minlength": true, "pattern": true, "placeholder": true, "readonly": true, "required": true, "size": true, }, "tel": { "autocomplete": true, "list": true, "maxlength": true, "minlength": true, "pattern": true, "placeholder": true, "readonly": true, "required": true, "size": true, }, "email": { "autocomplete": true, "list": true, "maxlength": true, "minlength": true, "multiple": true, "pattern": true, "placeholder": true, "readonly": true, "required": true, "size": true, }, "password": { "autocomplete": true, "maxlength": true, "minlength": true, "pattern": true, "placeholder": true, "readonly": true, "required": true, "size": true, }, "date": { "autocomplete": true, "list": true, "max": true, "min": true, "readonly": true, "required": true, "step": true, }, "month": { "autocomplete": true, "list": true, "max": true, "min": true, "readonly": true, "required": true, "step": true, }, "week": { "autocomplete": true, "list": true, "max": true, "min": true, "readonly": true, "required": true, "step": true, }, "time": { "autocomplete": true, "list": true, "max": true, "min": true, "readonly": true, "required": true, "step": true, }, "datetime-local": { "autocomplete": true, "list": true, "max": true, "min": true, "readonly": true, "required": true, "step": true, }, "number": { "autocomplete": true, "list": true, "max": true, "min": true, "placeholder": true, "readonly": true, "required": true, "step": true, }, "range": { "autocomplete": true, "list": true, "max": true, "min": true, "step": true, }, "color": { "autocomplete": true, "list": true, }, "checkbox": { "checked": true, "required": true, }, "radio": { "checked": true, "required": true, }, "file": { "accept": true, "capture": true, "multiple": true, "required": true, }, "submit": { "formaction": true, "formenctype": true, "formmethod": true, "formnovalidate": true, "formtarget": true, }, "image": { "alt": true, "formaction": true, "formenctype": true, "formmethod": true, "formnovalidate": true, "formtarget": true, "height": true, "src": true, "width": true, }, "reset": {}, "button": {}, "hidden": { "autocomplete": true, }, }
InputTypeAttributes maps input types to their supported attributes. Attributes not listed here may still be valid globally.
var InputTypeRoles = map[string]string{
"button": "button",
"checkbox": "checkbox",
"email": "textbox",
"image": "button",
"number": "spinbutton",
"radio": "radio",
"range": "slider",
"reset": "button",
"search": "searchbox",
"submit": "button",
"tel": "textbox",
"text": "textbox",
"url": "textbox",
}
InputTypeRoles maps input types to their implicit ARIA roles.
var LabelableElements = map[string]bool{ "button": true, "input": true, "meter": true, "output": true, "progress": true, "select": true, "textarea": true, }
LabelableElements are HTML elements that can be associated with a <label>.
var LandmarkElements = map[string]string{
"aside": "complementary",
"footer": "contentinfo",
"form": "form",
"header": "banner",
"main": "main",
"nav": "navigation",
"section": "region",
}
LandmarkElements maps HTML elements to their implicit ARIA landmark role.
var NonDeprecatedSizeAttrs = map[string]bool{ "img": true, "video": true, "canvas": true, "svg": true, "embed": true, "object": true, "iframe": true, }
NonDeprecatedSizeAttrs lists elements where width/height are NOT deprecated. These elements have intrinsic dimensions that should be specified in HTML.
var RequiredAncestors = map[string][]string{
"li": {"ul", "ol", "menu"},
"dt": {"dl"},
"dd": {"dl"},
"td": {"table"},
"th": {"table"},
"tr": {"table"},
"thead": {"table"},
"tbody": {"table"},
"tfoot": {"table"},
"caption": {"table"},
"colgroup": {"table"},
"col": {"colgroup"},
"legend": {"fieldset"},
"optgroup": {"select"},
"option": {"select", "optgroup", "datalist"},
"source": {"audio", "video", "picture"},
"track": {"audio", "video"},
"area": {"map"},
"figcaption": {"figure"},
"summary": {"details"},
"rt": {"ruby"},
"rp": {"ruby"},
}
RequiredAncestors maps elements to their required ancestor elements. The element must have at least one of these as an ancestor.
var UniqueElements = map[string]string{
"title": "head",
"base": "head",
"main": "body",
"caption": "table",
"thead": "table",
"tfoot": "table",
"summary": "details",
"legend": "fieldset",
}
UniqueElements are elements that should appear at most once in their context.
var ValidAnchorRels = map[string]bool{ "alternate": true, "author": true, "bookmark": true, "external": true, "help": true, "license": true, "me": true, "next": true, "nofollow": true, "noopener": true, "noreferrer": true, "opener": true, "prev": true, "privacy-policy": true, "search": true, "tag": true, "terms-of-service": true, }
ValidAnchorRels lists valid values for <a rel="">.
var ValidButtonTypes = map[string]bool{ "submit": true, "reset": true, "button": true, }
ValidButtonTypes lists valid values for <button type="">.
var ValidCrossOriginValues = map[string]bool{ "": true, "anonymous": true, "use-credentials": true, }
ValidCrossOriginValues lists valid values for crossorigin="" attribute.
ValidDecodingValues lists valid values for decoding="" attribute.
ValidDirValues lists valid values for dir="" attribute.
var ValidElements = map[string]bool{}/* 115 elements not displayed */
ValidElements is the set of standard HTML5 element names. Custom elements (containing hyphen) are handled separately.
var ValidFormEnctypes = map[string]bool{ "application/x-www-form-urlencoded": true, "multipart/form-data": true, "text/plain": true, }
ValidFormEnctypes lists valid values for <form enctype="">.
ValidFormMethods lists valid values for <form method="">.
var ValidInputTypes = map[string]bool{ "button": true, "checkbox": true, "color": true, "date": true, "datetime-local": true, "email": true, "file": true, "hidden": true, "image": true, "month": true, "number": true, "password": true, "radio": true, "range": true, "reset": true, "search": true, "submit": true, "tel": true, "text": true, "time": true, "url": true, "week": true, }
ValidInputTypes lists valid values for <input type="">.
var ValidLinkRels = map[string]bool{ "alternate": true, "author": true, "canonical": true, "dns-prefetch": true, "expect": true, "help": true, "icon": true, "license": true, "manifest": true, "modulepreload": true, "next": true, "pingback": true, "preconnect": true, "prefetch": true, "preload": true, "prerender": true, "prev": true, "privacy-policy": true, "search": true, "stylesheet": true, "terms-of-service": true, }
ValidLinkRels lists valid values for <link rel="">.
var ValidLoadingValues = map[string]bool{ "eager": true, "lazy": true, }
ValidLoadingValues lists valid values for loading="" attribute.
var ValidReferrerPolicies = map[string]bool{ "": true, "no-referrer": true, "no-referrer-when-downgrade": true, "origin": true, "origin-when-cross-origin": true, "same-origin": true, "strict-origin": true, "strict-origin-when-cross-origin": true, "unsafe-url": true, }
ValidReferrerPolicies lists valid values for referrerpolicy="" attribute.
var ValidSandboxTokens = map[string]bool{ "allow-downloads": true, "allow-forms": true, "allow-modals": true, "allow-orientation-lock": true, "allow-pointer-lock": true, "allow-popups": true, "allow-popups-to-escape-sandbox": true, "allow-presentation": true, "allow-same-origin": true, "allow-scripts": true, "allow-storage-access-by-user-activation": true, "allow-top-navigation": true, "allow-top-navigation-by-user-activation": true, "allow-top-navigation-to-custom-protocols": true, }
ValidSandboxTokens lists valid tokens for iframe sandbox="" attribute.
var ValidScopeValues = map[string]bool{ "row": true, "col": true, "rowgroup": true, "colgroup": true, }
ValidScopeValues lists valid values for <th scope="">.
var ValidScriptTypes = map[string]bool{ "": true, "text/javascript": true, "application/javascript": true, "text/ecmascript": true, "application/ecmascript": true, "module": true, "importmap": true, "speculationrules": true, "text/html": true, "application/json": true, "application/ld+json": true, "text/plain": true, }
ValidScriptTypes lists valid MIME types for <script type="">. Empty string is also valid (defaults to JavaScript).
var ValidTargets = map[string]bool{ "_self": true, "_blank": true, "_parent": true, "_top": true, }
ValidTargets lists valid values for target attribute.
var VoidElements = map[string]bool{ "area": true, "base": true, "br": true, "col": true, "embed": true, "hr": true, "img": true, "input": true, "link": true, "meta": true, "param": true, "source": true, "track": true, "wbr": true, }
VoidElements are HTML elements that cannot have content (self-closing). Per HTML5 spec: https://html.spec.whatwg.org/multipage/syntax.html#void-elements
Functions ¶
func AncestorWithTag ¶
AncestorWithTag walks up the tree looking for an ancestor with the given tag. Returns the first matching ancestor or nil if none found.
func ChildElements ¶
ChildElements returns only element node children (excludes text, comments, etc.).
func CountChildrenWithTag ¶
CountChildrenWithTag counts direct children matching the given tag.
func FindDescendant ¶
FindDescendant searches for a descendant matching predicate (depth-first). Returns the first match or nil if none found.
func FirstChildElement ¶
FirstChildElement returns the first element child, or nil if none.
func GetAccessibleName ¶
GetAccessibleName returns the accessible name from aria-label or aria-labelledby. Returns empty string if no accessible name is set.
func GetImplicitRole ¶
GetImplicitRole returns the implicit ARIA role for an element.
func HasAccessibleName ¶
HasAccessibleName checks if an element has an accessible name via: aria-label, aria-labelledby, title, text content, or child img/svg with alt.
func HasAncestor ¶
HasAncestor returns true if the node has an ancestor matching any of the given tags.
func HasChildWithTag ¶
HasChildWithTag returns true if there's a direct child with the given tag.
func HasDescendant ¶
HasDescendant returns true if any descendant matches predicate.
func HasUTF8BOM ¶
HasUTF8BOM checks if content starts with UTF-8 BOM bytes. This helper can be used by the linter before parsing.
func HeadingRank ¶
HeadingRank returns the numeric rank of a heading (1-6), or 0 if not a heading.
func IsCustomElement ¶
IsCustomElement returns true if the element is a valid custom element name. Custom elements must contain a hyphen and start with a lowercase letter.
func IsElementNode ¶
IsElementNode returns true if node is an HTML element.
func IsHTMXAttribute ¶ added in v0.5.0
IsHTMXAttribute checks if an attribute name is an htmx attribute pattern. Returns true if the attribute starts with "hx-" or matches "hx-on:*" pattern.
func IsTemplateExpr ¶
IsTemplateExpr returns true if value contains template placeholder.
func NormalizeText ¶
NormalizeText collapses whitespace and lowercases text for comparison. Removes template placeholders (TMPL) used during parsing.
func ValidateHTMXAttribute ¶ added in v0.5.0
ValidateHTMXAttribute checks if an htmx attribute is valid for the given version. Returns (valid, deprecated, v4Only). - valid: attribute is recognized as an htmx attribute for this version - deprecated: attribute is deprecated in this version (v4 only) - v4Only: attribute is only available in v4 (when using v2)
Types ¶
type AllowedLinks ¶
type AllowedLinks struct{}
AllowedLinks checks that link hrefs are valid.
func (*AllowedLinks) Check ¶
func (r *AllowedLinks) Check(doc *parser.Document) []Result
Check examines the document for problematic link hrefs.
func (*AllowedLinks) Description ¶
func (r *AllowedLinks) Description() string
Description returns what this rule checks.
type AreaAlt ¶
type AreaAlt struct{}
AreaAlt checks that <area> elements have alt text. Per WCAG 2.0 H24: Providing text alternatives for the area elements of image maps.
func (*AreaAlt) Description ¶
Description returns what this rule checks.
type AriaHiddenBody ¶
type AriaHiddenBody struct{}
AriaHiddenBody checks that aria-hidden is not set on the body element.
func (*AriaHiddenBody) Description ¶
func (r *AriaHiddenBody) Description() string
func (*AriaHiddenBody) Name ¶
func (r *AriaHiddenBody) Name() string
type AriaLabelMisuse ¶
type AriaLabelMisuse struct{}
AriaLabelMisuse checks for aria-label on elements that don't support it.
func (*AriaLabelMisuse) Description ¶
func (r *AriaLabelMisuse) Description() string
func (*AriaLabelMisuse) Name ¶
func (r *AriaLabelMisuse) Name() string
type AttrSpec ¶
type AttrSpec struct {
// Type indicates how the value should be validated.
Type AttrType
// AllowedValues lists valid values for AttrTypeEnum.
AllowedValues []string
// Pattern is a regex for AttrTypePattern.
Pattern string
// Required indicates the attribute must be present.
Required bool
// Deprecated: indicates the attribute should not be used.
Deprecated bool
// DeprecatedMessage provides guidance on what to use instead.
DeprecatedMessage string
// ValidFor lists elements this attribute is valid on (empty = global).
ValidFor []string
}
AttrSpec defines an attribute's constraints.
type AttrType ¶
type AttrType int
AttrType indicates the type of attribute value validation.
const ( AttrTypeString AttrType = iota // Any string value AttrTypeEnum // Must be one of AllowedValues AttrTypeBoolean // Boolean attribute (presence-based) AttrTypePattern // Must match Pattern regex AttrTypeID // Valid ID value AttrTypeIDRef // Reference to an ID AttrTypeIDRefList // Space-separated list of ID refs AttrTypeURL // Valid URL AttrTypeInteger // Integer value AttrTypePositive // Positive integer )
type AttributeAllowedValues ¶
type AttributeAllowedValues struct{}
AttributeAllowedValues checks that attributes have valid values.
func (*AttributeAllowedValues) Check ¶
func (r *AttributeAllowedValues) Check(doc *parser.Document) []Result
Check examines the document for attributes with invalid values.
func (*AttributeAllowedValues) Description ¶
func (r *AttributeAllowedValues) Description() string
Description returns what this rule checks.
func (*AttributeAllowedValues) Name ¶
func (r *AttributeAllowedValues) Name() string
Name returns the rule identifier.
type AttributeMisuse ¶
type AttributeMisuse struct {
// contains filtered or unexported fields
}
AttributeMisuse checks that attributes are used on correct elements.
func (*AttributeMisuse) Check ¶
func (r *AttributeMisuse) Check(doc *parser.Document) []Result
Check examines the document for misused attributes.
func (*AttributeMisuse) Configure ¶ added in v0.7.0
func (r *AttributeMisuse) Configure(htmxEnabled bool, _ string)
Configure implements HTMXConfigurable.
func (*AttributeMisuse) Description ¶
func (r *AttributeMisuse) Description() string
Description returns what this rule checks.
func (*AttributeMisuse) Name ¶
func (r *AttributeMisuse) Name() string
Name returns the rule identifier.
type ButtonName ¶
type ButtonName struct{}
ButtonName checks that buttons have accessible names.
func (*ButtonName) Description ¶
func (r *ButtonName) Description() string
func (*ButtonName) Name ¶
func (r *ButtonName) Name() string
type ButtonType ¶
type ButtonType struct{}
ButtonType checks that buttons have explicit type attributes.
func (*ButtonType) Description ¶
func (r *ButtonType) Description() string
func (*ButtonType) Name ¶
func (r *ButtonType) Name() string
type ClassPattern ¶
ClassPattern checks that class names follow a naming convention.
func (*ClassPattern) Check ¶
func (r *ClassPattern) Check(doc *parser.Document) []Result
Check examines the document for class names not matching pattern.
func (*ClassPattern) Description ¶
func (r *ClassPattern) Description() string
Description returns what this rule checks.
type ContentModel ¶
type ContentModel int
ContentModel represents HTML5 content model categories.
const ( ModelNone ContentModel = 0 ModelFlow ContentModel = 1 << iota // Most elements in body ModelPhrasing // Text-level elements ModelInteractive // User-interactive elements ModelHeading // h1-h6 ModelSectioning // article, aside, nav, section ModelEmbedded // img, video, audio, etc. ModelMetadata // head elements ModelTransparent // Inherits parent's content model )
type Deprecated ¶
type Deprecated struct{}
Deprecated checks for deprecated HTML elements.
func (*Deprecated) Check ¶
func (r *Deprecated) Check(doc *parser.Document) []Result
Check examines the document for deprecated elements.
func (*Deprecated) Description ¶
func (r *Deprecated) Description() string
Description returns what this rule checks.
type DoctypeHTML ¶
type DoctypeHTML struct{}
DoctypeHTML checks that DOCTYPE is the HTML5 doctype.
func (*DoctypeHTML) Check ¶
func (r *DoctypeHTML) Check(doc *parser.Document) []Result
Check examines the document for non-HTML5 doctypes.
func (*DoctypeHTML) Description ¶
func (r *DoctypeHTML) Description() string
Description returns what this rule checks.
type DuplicateID ¶
type DuplicateID struct{}
DuplicateID checks that id attributes are unique within a document.
func (*DuplicateID) Description ¶
func (r *DuplicateID) Description() string
func (*DuplicateID) Name ¶
func (r *DuplicateID) Name() string
type ElementName ¶
type ElementName struct{}
ElementName checks that element names are valid.
func (*ElementName) Check ¶
func (r *ElementName) Check(doc *parser.Document) []Result
Check examines the document for invalid element names.
func (*ElementName) Description ¶
func (r *ElementName) Description() string
Description returns what this rule checks.
type ElementPermittedContent ¶
type ElementPermittedContent struct{}
ElementPermittedContent checks that elements contain only permitted children.
func (*ElementPermittedContent) Check ¶
func (r *ElementPermittedContent) Check(doc *parser.Document) []Result
Check examines the document for elements with invalid children.
func (*ElementPermittedContent) Description ¶
func (r *ElementPermittedContent) Description() string
Description returns what this rule checks.
func (*ElementPermittedContent) Name ¶
func (r *ElementPermittedContent) Name() string
Name returns the rule identifier.
type ElementPermittedOccurrences ¶
type ElementPermittedOccurrences struct{}
ElementPermittedOccurrences checks cardinality constraints (e.g., one title per head).
func (*ElementPermittedOccurrences) Check ¶
func (r *ElementPermittedOccurrences) Check(doc *parser.Document) []Result
Check examines the document for elements appearing more than allowed.
func (*ElementPermittedOccurrences) Description ¶
func (r *ElementPermittedOccurrences) Description() string
Description returns what this rule checks.
func (*ElementPermittedOccurrences) Name ¶
func (r *ElementPermittedOccurrences) Name() string
Name returns the rule identifier.
type ElementPermittedOrder ¶
type ElementPermittedOrder struct{}
ElementPermittedOrder checks that elements appear in correct order.
func (*ElementPermittedOrder) Check ¶
func (r *ElementPermittedOrder) Check(doc *parser.Document) []Result
Check examines the document for incorrectly ordered elements.
func (*ElementPermittedOrder) Description ¶
func (r *ElementPermittedOrder) Description() string
Description returns what this rule checks.
func (*ElementPermittedOrder) Name ¶
func (r *ElementPermittedOrder) Name() string
Name returns the rule identifier.
type ElementPermittedParent ¶
type ElementPermittedParent struct{}
ElementPermittedParent checks that elements have valid parent elements.
func (*ElementPermittedParent) Check ¶
func (r *ElementPermittedParent) Check(doc *parser.Document) []Result
Check examines the document for elements with invalid parents.
func (*ElementPermittedParent) Description ¶
func (r *ElementPermittedParent) Description() string
Description returns what this rule checks.
func (*ElementPermittedParent) Name ¶
func (r *ElementPermittedParent) Name() string
Name returns the rule identifier.
type ElementRequiredAncestor ¶
type ElementRequiredAncestor struct{}
ElementRequiredAncestor checks that elements have their required ancestors.
func (*ElementRequiredAncestor) Check ¶
func (r *ElementRequiredAncestor) Check(doc *parser.Document) []Result
Check examines the document for elements missing required ancestors.
func (*ElementRequiredAncestor) Description ¶
func (r *ElementRequiredAncestor) Description() string
Description returns what this rule checks.
func (*ElementRequiredAncestor) Name ¶
func (r *ElementRequiredAncestor) Name() string
Name returns the rule identifier.
type ElementRequiredAttributes ¶
type ElementRequiredAttributes struct{}
ElementRequiredAttributes checks that elements have their required attributes.
func (*ElementRequiredAttributes) Check ¶
func (r *ElementRequiredAttributes) Check(doc *parser.Document) []Result
Check examines the document for elements missing required attributes.
func (*ElementRequiredAttributes) Description ¶
func (r *ElementRequiredAttributes) Description() string
Description returns what this rule checks.
func (*ElementRequiredAttributes) Name ¶
func (r *ElementRequiredAttributes) Name() string
Name returns the rule identifier.
type ElementRequiredContent ¶
type ElementRequiredContent struct{}
ElementRequiredContent checks that elements have their required children.
func (*ElementRequiredContent) Check ¶
func (r *ElementRequiredContent) Check(doc *parser.Document) []Result
Check examines the document for elements missing required children.
func (*ElementRequiredContent) Description ¶
func (r *ElementRequiredContent) Description() string
Description returns what this rule checks.
func (*ElementRequiredContent) Name ¶
func (r *ElementRequiredContent) Name() string
Name returns the rule identifier.
type ElementSpec ¶
type ElementSpec struct {
// ContentModel indicates what kind of content the element represents.
ContentModel ContentModel
// PermittedContent specifies allowed child element categories or specific tags.
// Empty means element can contain any flow content.
PermittedContent []string
// ForbiddenContent specifies elements that cannot be descendants.
ForbiddenContent []string
// PermittedParents specifies allowed parent elements.
// Empty means any element accepting the content model.
PermittedParents []string
// RequiredParent specifies a parent that must exist (not necessarily direct).
RequiredParent string
// RequiredChildren specifies children that must exist.
RequiredChildren []string
// RequiredAttributes lists attributes that must be present.
RequiredAttributes []string
// VoidElement is true for elements that cannot have children (br, img, etc.).
VoidElement bool
// Deprecated: indicates the element should not be used.
Deprecated bool
// DeprecatedMessage provides guidance on what to use instead.
DeprecatedMessage string
}
ElementSpec defines an HTML element's constraints per HTML5 spec.
type EmptyTitle ¶
type EmptyTitle struct{}
EmptyTitle checks that title elements have text content.
func (*EmptyTitle) Description ¶
func (r *EmptyTitle) Description() string
func (*EmptyTitle) Name ¶
func (r *EmptyTitle) Name() string
type FormDupName ¶
type FormDupName struct{}
FormDupName checks for duplicate name attributes within a form. Radio buttons and checkboxes with the same name are allowed.
func (*FormDupName) Check ¶
func (r *FormDupName) Check(doc *parser.Document) []Result
Check examines the document for duplicate names within forms.
func (*FormDupName) Description ¶
func (r *FormDupName) Description() string
Description returns what this rule checks.
type FormSubmit ¶
type FormSubmit struct{}
FormSubmit checks that forms have submit buttons (WCAG H32).
func (*FormSubmit) Description ¶
func (r *FormSubmit) Description() string
func (*FormSubmit) Name ¶
func (r *FormSubmit) Name() string
type HTMXAttributes ¶ added in v0.7.0
type HTMXAttributes struct {
// contains filtered or unexported fields
}
HTMXAttributes validates htmx attribute values.
func (*HTMXAttributes) Check ¶ added in v0.7.0
func (r *HTMXAttributes) Check(doc *parser.Document) []Result
Check examines the document for invalid htmx attribute values.
func (*HTMXAttributes) Configure ¶ added in v0.7.0
func (r *HTMXAttributes) Configure(htmxEnabled bool, htmxVersion string)
Configure implements HTMXConfigurable.
func (*HTMXAttributes) Description ¶ added in v0.7.0
func (r *HTMXAttributes) Description() string
Description returns what this rule checks.
func (*HTMXAttributes) Name ¶ added in v0.7.0
func (r *HTMXAttributes) Name() string
Name returns the rule identifier.
type HTMXConfigurable ¶ added in v0.5.0
HTMXConfigurable is implemented by rules that need htmx configuration.
type HeadingContent ¶
type HeadingContent struct{}
HeadingContent checks that heading elements have text content.
func (*HeadingContent) Description ¶
func (r *HeadingContent) Description() string
func (*HeadingContent) Name ¶
func (r *HeadingContent) Name() string
type HeadingLevel ¶
type HeadingLevel struct{}
HeadingLevel checks that heading levels don't skip (e.g., h1 to h3).
func (*HeadingLevel) Description ¶
func (r *HeadingLevel) Description() string
func (*HeadingLevel) Name ¶
func (r *HeadingLevel) Name() string
type HiddenFocusable ¶
type HiddenFocusable struct{}
HiddenFocusable checks that aria-hidden elements don't contain focusable content.
func (*HiddenFocusable) Description ¶
func (r *HiddenFocusable) Description() string
func (*HiddenFocusable) Name ¶
func (r *HiddenFocusable) Name() string
type IDPattern ¶
IDPattern checks that id attributes follow a naming convention.
func (*IDPattern) Description ¶
Description returns what this rule checks.
type ImgAlt ¶
type ImgAlt struct{}
ImgAlt checks that all img elements have alt attributes.
func (*ImgAlt) Description ¶
type InputAttributes ¶
type InputAttributes struct {
// contains filtered or unexported fields
}
InputAttributes checks that input elements only have type-appropriate attributes.
func (*InputAttributes) Check ¶
func (r *InputAttributes) Check(doc *parser.Document) []Result
Check examines the document for invalid input attribute combinations.
func (*InputAttributes) Configure ¶ added in v0.5.0
func (r *InputAttributes) Configure(htmxEnabled bool, htmxVersion string)
Configure sets the htmx configuration for this rule.
func (*InputAttributes) Description ¶
func (r *InputAttributes) Description() string
Description returns what this rule checks.
func (*InputAttributes) Name ¶
func (r *InputAttributes) Name() string
Name returns the rule identifier.
type InputAttributesConfig ¶ added in v0.5.0
type InputAttributesConfig struct {
// HTMXEnabled allows htmx attributes on input elements.
HTMXEnabled bool
// HTMXVersion specifies which htmx version to validate ("2" or "4").
HTMXVersion string
}
InputAttributesConfig holds htmx configuration for the InputAttributes rule.
type InputLabel ¶
type InputLabel struct{}
InputLabel checks that form inputs have associated labels.
func (*InputLabel) Description ¶
func (r *InputLabel) Description() string
func (*InputLabel) Name ¶
func (r *InputLabel) Name() string
type LinkName ¶
type LinkName struct{}
LinkName checks that links have accessible names.
func (*LinkName) Description ¶
type LongTitle ¶
type LongTitle struct{}
LongTitle checks that title elements don't exceed recommended length.
func (*LongTitle) Description ¶
type MapDupName ¶
type MapDupName struct{}
MapDupName checks for duplicate area names within a map element.
func (*MapDupName) Check ¶
func (r *MapDupName) Check(doc *parser.Document) []Result
Check examines the document for duplicate area names within maps.
func (*MapDupName) Description ¶
func (r *MapDupName) Description() string
Description returns what this rule checks.
type MapIDName ¶
type MapIDName struct{}
MapIDName checks that map elements have matching id and name attributes.
func (*MapIDName) Description ¶
Description returns what this rule checks.
type MetaRefresh ¶
type MetaRefresh struct{}
MetaRefresh checks for auto-refresh meta tags.
func (*MetaRefresh) Description ¶
func (r *MetaRefresh) Description() string
func (*MetaRefresh) Name ¶
func (r *MetaRefresh) Name() string
type MissingDoctype ¶
type MissingDoctype struct{}
MissingDoctype checks that a DOCTYPE declaration is present.
func (*MissingDoctype) Check ¶
func (r *MissingDoctype) Check(doc *parser.Document) []Result
Check examines the document for missing DOCTYPE.
func (*MissingDoctype) Description ¶
func (r *MissingDoctype) Description() string
Description returns what this rule checks.
func (*MissingDoctype) Name ¶
func (r *MissingDoctype) Name() string
Name returns the rule identifier.
type MultipleLabeledControls ¶
type MultipleLabeledControls struct{}
MultipleLabeledControls checks that labels don't reference multiple controls.
func (*MultipleLabeledControls) Check ¶
func (r *MultipleLabeledControls) Check(doc *parser.Document) []Result
func (*MultipleLabeledControls) Description ¶
func (r *MultipleLabeledControls) Description() string
func (*MultipleLabeledControls) Name ¶
func (r *MultipleLabeledControls) Name() string
type NamePattern ¶
NamePattern checks that name attributes follow a naming convention.
func (*NamePattern) Check ¶
func (r *NamePattern) Check(doc *parser.Document) []Result
Check examines the document for name values not matching pattern.
func (*NamePattern) Description ¶
func (r *NamePattern) Description() string
Description returns what this rule checks.
type NoAbstractRole ¶
type NoAbstractRole struct{}
NoAbstractRole checks for abstract ARIA roles that shouldn't be used.
func (*NoAbstractRole) Description ¶
func (r *NoAbstractRole) Description() string
func (*NoAbstractRole) Name ¶
func (r *NoAbstractRole) Name() string
type NoAutoplay ¶
type NoAutoplay struct{}
NoAutoplay checks that media elements don't autoplay.
func (*NoAutoplay) Description ¶
func (r *NoAutoplay) Description() string
func (*NoAutoplay) Name ¶
func (r *NoAutoplay) Name() string
type NoConditionalComment ¶
type NoConditionalComment struct{}
NoConditionalComment checks for IE conditional comments.
func (*NoConditionalComment) Check ¶
func (r *NoConditionalComment) Check(doc *parser.Document) []Result
Check examines the document for IE conditional comments.
func (*NoConditionalComment) Description ¶
func (r *NoConditionalComment) Description() string
Description returns what this rule checks.
func (*NoConditionalComment) Name ¶
func (r *NoConditionalComment) Name() string
Name returns the rule identifier.
type NoDeprecatedAttr ¶
type NoDeprecatedAttr struct{}
NoDeprecatedAttr checks for deprecated HTML attributes.
func (*NoDeprecatedAttr) Check ¶
func (r *NoDeprecatedAttr) Check(doc *parser.Document) []Result
Check examines the document for deprecated attributes.
func (*NoDeprecatedAttr) Description ¶
func (r *NoDeprecatedAttr) Description() string
Description returns what this rule checks.
func (*NoDeprecatedAttr) Name ¶
func (r *NoDeprecatedAttr) Name() string
Name returns the rule identifier.
type NoDupAttr ¶
type NoDupAttr struct{}
NoDupAttr checks for duplicate attributes on an element. Note: The Go HTML parser already handles this by keeping the first occurrence, so this rule may not catch duplicates in the raw HTML. It validates the parsed result.
func (*NoDupAttr) Description ¶
Description returns what this rule checks.
type NoDupClass ¶
type NoDupClass struct{}
NoDupClass checks for duplicate class names within a class attribute.
func (*NoDupClass) Check ¶
func (r *NoDupClass) Check(doc *parser.Document) []Result
Check examines the document for duplicate class names.
func (*NoDupClass) Description ¶
func (r *NoDupClass) Description() string
Description returns what this rule checks.
type NoImplicitInputType ¶
type NoImplicitInputType struct{}
NoImplicitInputType suggests explicit type attribute on input elements.
func (*NoImplicitInputType) Check ¶
func (r *NoImplicitInputType) Check(doc *parser.Document) []Result
Check examines the document for inputs without type.
func (*NoImplicitInputType) Description ¶
func (r *NoImplicitInputType) Description() string
Description returns what this rule checks.
func (*NoImplicitInputType) Name ¶
func (r *NoImplicitInputType) Name() string
Name returns the rule identifier.
type NoInlineStyle ¶
type NoInlineStyle struct{}
NoInlineStyle checks for inline style attributes.
func (*NoInlineStyle) Description ¶
func (r *NoInlineStyle) Description() string
func (*NoInlineStyle) Name ¶
func (r *NoInlineStyle) Name() string
type NoMissingReferences ¶
type NoMissingReferences struct{}
NoMissingReferences checks that ID references point to existing elements.
func (*NoMissingReferences) Check ¶
func (r *NoMissingReferences) Check(doc *parser.Document) []Result
Check examines the document for broken ID references.
func (*NoMissingReferences) Description ¶
func (r *NoMissingReferences) Description() string
Description returns what this rule checks.
func (*NoMissingReferences) Name ¶
func (r *NoMissingReferences) Name() string
Name returns the rule identifier.
type NoMultipleMain ¶
type NoMultipleMain struct{}
NoMultipleMain ensures only one visible <main> element per document.
func (*NoMultipleMain) Description ¶
func (r *NoMultipleMain) Description() string
func (*NoMultipleMain) Name ¶
func (r *NoMultipleMain) Name() string
type NoRedundantFor ¶
type NoRedundantFor struct{}
NoRedundantFor checks for label elements with for attribute when they wrap the control.
func (*NoRedundantFor) Check ¶
func (r *NoRedundantFor) Check(doc *parser.Document) []Result
Check examines the document for redundant for attributes on labels.
func (*NoRedundantFor) Description ¶
func (r *NoRedundantFor) Description() string
Description returns what this rule checks.
func (*NoRedundantFor) Name ¶
func (r *NoRedundantFor) Name() string
Name returns the rule identifier.
type NoRedundantRole ¶
type NoRedundantRole struct{}
NoRedundantRole checks for explicit roles that match implicit roles.
func (*NoRedundantRole) Description ¶
func (r *NoRedundantRole) Description() string
func (*NoRedundantRole) Name ¶
func (r *NoRedundantRole) Name() string
type NoStyleTag ¶
type NoStyleTag struct{}
NoStyleTag discourages use of inline <style> tags.
func (*NoStyleTag) Check ¶
func (r *NoStyleTag) Check(doc *parser.Document) []Result
Check examines the document for <style> tags.
func (*NoStyleTag) Description ¶
func (r *NoStyleTag) Description() string
Description returns what this rule checks.
type NoUTF8BOM ¶
type NoUTF8BOM struct{}
NoUTF8BOM checks that files don't start with a UTF-8 BOM.
func (*NoUTF8BOM) Check ¶
Check examines the document for UTF-8 BOM. Note: This check needs raw file content, which the parser may strip. The linter should check for BOM before parsing if needed.
func (*NoUTF8BOM) Description ¶
Description returns what this rule checks.
type PreferAria ¶
type PreferAria struct{}
PreferAria checks for custom data attributes that should use ARIA equivalents.
func (*PreferAria) Description ¶
func (r *PreferAria) Description() string
func (*PreferAria) Name ¶
func (r *PreferAria) Name() string
type PreferButton ¶
type PreferButton struct{}
PreferButton checks for input elements that should be buttons.
func (*PreferButton) Description ¶
func (r *PreferButton) Description() string
func (*PreferButton) Name ¶
func (r *PreferButton) Name() string
type PreferNativeElement ¶
type PreferNativeElement struct{}
PreferNativeElement checks for ARIA roles that have native HTML equivalents.
func (*PreferNativeElement) Check ¶
func (r *PreferNativeElement) Check(doc *parser.Document) []Result
func (*PreferNativeElement) Description ¶
func (r *PreferNativeElement) Description() string
func (*PreferNativeElement) Name ¶
func (r *PreferNativeElement) Name() string
type PreferSemantic ¶
type PreferSemantic struct{}
PreferSemantic checks for non-semantic elements used as interactive controls.
func (*PreferSemantic) Description ¶
func (r *PreferSemantic) Description() string
func (*PreferSemantic) Name ¶
func (r *PreferSemantic) Name() string
type PreferTbody ¶
type PreferTbody struct{}
PreferTbody suggests using explicit tbody in tables.
func (*PreferTbody) Check ¶
func (r *PreferTbody) Check(doc *parser.Document) []Result
Check examines the document for tables without explicit tbody.
func (*PreferTbody) Description ¶
func (r *PreferTbody) Description() string
Description returns what this rule checks.
type RawRule ¶ added in v0.9.0
RawRule is implemented by rules that need access to the raw file content before template preprocessing. This allows linting template syntax itself.
type RedundantAriaLabel ¶
type RedundantAriaLabel struct{}
RedundantAriaLabel checks for aria-label that duplicates visible text.
func (*RedundantAriaLabel) Check ¶
func (r *RedundantAriaLabel) Check(doc *parser.Document) []Result
func (*RedundantAriaLabel) Description ¶
func (r *RedundantAriaLabel) Description() string
func (*RedundantAriaLabel) Name ¶
func (r *RedundantAriaLabel) Name() string
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds all available rules.
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry creates a registry with all default rules.
type RequireCSPNonce ¶
type RequireCSPNonce struct{}
RequireCSPNonce checks that inline scripts and styles have CSP nonce.
func (*RequireCSPNonce) Check ¶
func (r *RequireCSPNonce) Check(doc *parser.Document) []Result
Check examines the document for inline scripts/styles without nonce.
func (*RequireCSPNonce) Description ¶
func (r *RequireCSPNonce) Description() string
Description returns what this rule checks.
func (*RequireCSPNonce) Name ¶
func (r *RequireCSPNonce) Name() string
Name returns the rule identifier.
type RequireLang ¶
type RequireLang struct{}
RequireLang ensures <html> elements have a lang attribute.
func (*RequireLang) Description ¶
func (r *RequireLang) Description() string
func (*RequireLang) Name ¶
func (r *RequireLang) Name() string
type RequireSRI ¶
type RequireSRI struct{}
RequireSRI checks that external scripts and stylesheets have integrity attributes.
func (*RequireSRI) Description ¶
func (r *RequireSRI) Description() string
func (*RequireSRI) Name ¶
func (r *RequireSRI) Name() string
type Result ¶
type Result struct {
Rule string // Rule name (e.g., "img-alt")
Message string // Human-readable description
Filename string // Source file path
Line int // 1-indexed line number
Col int // 1-indexed column number
Severity Severity // Error, Warning, or Info
}
Result represents a single lint finding.
type Rule ¶
type Rule interface {
// Name returns the rule identifier (e.g., "img-alt")
Name() string
// Description returns a brief explanation of what the rule checks
Description() string
// Check examines a document and returns any violations found
Check(doc *parser.Document) []Result
}
Rule defines the interface for accessibility rules.
type SVGFocusable ¶
type SVGFocusable struct{}
SVGFocusable checks that SVGs inside interactive elements have focusable="false".
func (*SVGFocusable) Description ¶
func (r *SVGFocusable) Description() string
func (*SVGFocusable) Name ¶
func (r *SVGFocusable) Name() string
type ScriptElement ¶
type ScriptElement struct{}
ScriptElement checks script element constraints.
func (*ScriptElement) Check ¶
func (r *ScriptElement) Check(doc *parser.Document) []Result
Check examines the document for script element issues.
func (*ScriptElement) Description ¶
func (r *ScriptElement) Description() string
Description returns what this rule checks.
func (*ScriptElement) Name ¶
func (r *ScriptElement) Name() string
Name returns the rule identifier.
type ScriptType ¶
type ScriptType struct{}
ScriptType checks that script elements have valid type attributes.
func (*ScriptType) Check ¶
func (r *ScriptType) Check(doc *parser.Document) []Result
Check examines the document for script elements with invalid type.
func (*ScriptType) Description ¶
func (r *ScriptType) Description() string
Description returns what this rule checks.
type TabindexNoPositive ¶
type TabindexNoPositive struct{}
TabindexNoPositive checks that tabindex values are not positive.
func (*TabindexNoPositive) Check ¶
func (r *TabindexNoPositive) Check(doc *parser.Document) []Result
func (*TabindexNoPositive) Description ¶
func (r *TabindexNoPositive) Description() string
func (*TabindexNoPositive) Name ¶
func (r *TabindexNoPositive) Name() string
type TelNonBreaking ¶
type TelNonBreaking struct{}
TelNonBreaking checks that tel: links use non-breaking formatting. Phone numbers should use or CSS to prevent awkward line breaks.
func (*TelNonBreaking) Check ¶
func (r *TelNonBreaking) Check(doc *parser.Document) []Result
Check examines the document for tel: links with breaking spaces.
func (*TelNonBreaking) Description ¶
func (r *TelNonBreaking) Description() string
Description returns what this rule checks.
func (*TelNonBreaking) Name ¶
func (r *TelNonBreaking) Name() string
Name returns the rule identifier.
type TemplateSyntaxValid ¶ added in v0.9.0
type TemplateSyntaxValid struct{}
TemplateSyntaxValid checks for basic Go template syntax errors.
func (*TemplateSyntaxValid) Check ¶ added in v0.9.0
func (r *TemplateSyntaxValid) Check(_ *parser.Document) []Result
Check implements Rule but returns nil - this rule uses CheckRaw instead.
func (*TemplateSyntaxValid) CheckRaw ¶ added in v0.9.0
func (r *TemplateSyntaxValid) CheckRaw(filename string, content []byte) []Result
CheckRaw examines the raw template content for syntax errors.
func (*TemplateSyntaxValid) Description ¶ added in v0.9.0
func (r *TemplateSyntaxValid) Description() string
func (*TemplateSyntaxValid) Name ¶ added in v0.9.0
func (r *TemplateSyntaxValid) Name() string
type TemplateWhitespaceTrim ¶ added in v0.9.0
type TemplateWhitespaceTrim struct{}
TemplateWhitespaceTrim checks for Go template actions that may create unwanted whitespace in output. It suggests using trim markers ({{- and -}}) to prevent empty lines in rendered output.
func (*TemplateWhitespaceTrim) Check ¶ added in v0.9.0
func (r *TemplateWhitespaceTrim) Check(_ *parser.Document) []Result
Check implements Rule but returns nil - this rule uses CheckRaw instead.
func (*TemplateWhitespaceTrim) CheckRaw ¶ added in v0.9.0
func (r *TemplateWhitespaceTrim) CheckRaw(filename string, content []byte) []Result
CheckRaw examines the raw template content for whitespace trim issues.
func (*TemplateWhitespaceTrim) Description ¶ added in v0.9.0
func (r *TemplateWhitespaceTrim) Description() string
func (*TemplateWhitespaceTrim) Name ¶ added in v0.9.0
func (r *TemplateWhitespaceTrim) Name() string
type TextContent ¶
type TextContent struct{}
TextContent checks that interactive elements have accessible text content. This is broader than button-name/link-name and covers other interactive elements.
func (*TextContent) Check ¶
func (r *TextContent) Check(doc *parser.Document) []Result
Check examines the document for interactive elements without text content.
func (*TextContent) Description ¶
func (r *TextContent) Description() string
Description returns what this rule checks.
type UniqueLandmark ¶
type UniqueLandmark struct{}
UniqueLandmark checks that duplicate landmark types have unique names.
func (*UniqueLandmark) Description ¶
func (r *UniqueLandmark) Description() string
func (*UniqueLandmark) Name ¶
func (r *UniqueLandmark) Name() string
type ValidAutocomplete ¶
type ValidAutocomplete struct{}
ValidAutocomplete checks that autocomplete attributes have valid values.
func (*ValidAutocomplete) Check ¶
func (r *ValidAutocomplete) Check(doc *parser.Document) []Result
Check examines the document for invalid autocomplete values.
func (*ValidAutocomplete) Description ¶
func (r *ValidAutocomplete) Description() string
Description returns what this rule checks.
func (*ValidAutocomplete) Name ¶
func (r *ValidAutocomplete) Name() string
Name returns the rule identifier.
type ValidID ¶
type ValidID struct{}
ValidID ensures ID attributes are well-formed.
func (*ValidID) Description ¶
type VoidContent ¶
type VoidContent struct{}
VoidContent checks that void elements have no children.
func (*VoidContent) Check ¶
func (r *VoidContent) Check(doc *parser.Document) []Result
Check examines the document for void elements with children.
func (*VoidContent) Description ¶
func (r *VoidContent) Description() string
Description returns what this rule checks.
type WcagH36 ¶
type WcagH36 struct{}
WcagH36 checks that input type="image" has alt text. Per WCAG H36: Using alt attributes on images used as submit buttons.
func (*WcagH36) Description ¶
Description returns what this rule checks.
type WcagH63 ¶
type WcagH63 struct{}
WcagH63 checks that th elements have scope attribute. Per WCAG H63: Using the scope attribute to associate header cells and data cells.
func (*WcagH63) Description ¶
Description returns what this rule checks.
type WcagH67 ¶
type WcagH67 struct{}
WcagH67 checks that decorative images have empty alt and no title. Per WCAG H67: Using null alt text and no title attribute for decorative images.
func (*WcagH67) Description ¶
Description returns what this rule checks.
type WcagH71 ¶
type WcagH71 struct{}
WcagH71 checks that fieldset elements contain a legend. Per WCAG H71: Providing a description for groups of form controls using fieldset and legend elements.
func (*WcagH71) Description ¶
Description returns what this rule checks.
Source Files
¶
- allowed_links.go
- area_alt.go
- aria_hidden_body.go
- aria_label_misuse.go
- attr_pattern.go
- attribute_allowed_values.go
- attribute_misuse.go
- attributes_spec.go
- button_name.go
- button_type.go
- deprecated.go
- deprecated_spec.go
- doctype.go
- duplicate_id.go
- element_name.go
- element_permitted_content.go
- element_permitted_occurrences.go
- element_permitted_order.go
- element_permitted_parent.go
- element_required_ancestor.go
- element_required_attributes.go
- element_required_content.go
- elements.go
- elements_spec.go
- empty_title.go
- form_dup_name.go
- form_submit.go
- heading_content.go
- heading_level.go
- helpers.go
- hidden_focusable.go
- htmlspec.go
- htmx.go
- htmx_attributes.go
- img_alt.go
- input_attributes.go
- input_label.go
- link_name.go
- long_title.go
- map_dup_name.go
- map_id_name.go
- meta_refresh.go
- multiple_labeled_controls.go
- no_abstract_role.go
- no_autoplay.go
- no_conditional_comment.go
- no_deprecated_attr.go
- no_dup_attr.go
- no_dup_class.go
- no_implicit_input_type.go
- no_inline_style.go
- no_missing_references.go
- no_multiple_main.go
- no_redundant_for.go
- no_redundant_role.go
- no_style_tag.go
- no_utf8_bom.go
- prefer_aria.go
- prefer_button.go
- prefer_native_element.go
- prefer_semantic.go
- prefer_tbody.go
- redundant_aria_label.go
- require_csp_nonce.go
- require_lang.go
- require_sri.go
- rule.go
- script_element.go
- script_type.go
- svg_focusable.go
- tabindex.go
- tel_non_breaking.go
- template_syntax_valid.go
- template_whitespace_trim.go
- text_content.go
- unique_landmark.go
- valid_autocomplete.go
- valid_id.go
- void_content.go
- wcag_h36.go
- wcag_h63.go
- wcag_h67.go
- wcag_h71.go