validation
Package validation provides accessibility validation and linting tools.
func ContrastRatio
func ContrastRatio(fg, bg rendering.Color) float64
ContrastRatio calculates the contrast ratio between two colors according to WCAG 2.1. Returns a value between 1 and 21, where higher values indicate more contrast. A ratio of 4.5:1 is required for normal text (AA), 7:1 for enhanced (AAA). A ratio of 3:1 is required for large text (AA), 4.5:1 for enhanced (AAA).
func GroupByRule
func GroupByRule(results []LintResult) map[LintRule][]LintResult
GroupByRule groups lint results by their rule.
func HasErrors
func HasErrors(results []LintResult) bool
HasErrors returns true if any lint results are errors.
func HasWarnings
func HasWarnings(results []LintResult) bool
HasWarnings returns true if any lint results are warnings or errors.
func IsLargeText
func IsLargeText(fontSizePx float64, isBold bool) bool
IsLargeText determines if text at the given font size and weight is considered "large" for WCAG contrast requirements. Large text is 18pt (24px) or larger, or 14pt (18.67px) bold or larger.
func MeetsWCAG
func MeetsWCAG(ratio float64, level WCAGLevel, textSize TextSize) bool
MeetsWCAG checks if a contrast ratio meets the specified WCAG level for the given text size.
func MeetsWCAGAA
func MeetsWCAGAA(ratio float64, largeText bool) bool
MeetsWCAGAA checks if a contrast ratio meets WCAG AA requirements. Pass largeText=true for text that is 18pt+ or 14pt+ bold.
func MeetsWCAGAAA
func MeetsWCAGAAA(ratio float64, largeText bool) bool
MeetsWCAGAAA checks if a contrast ratio meets WCAG AAA requirements. Pass largeText=true for text that is 18pt+ or 14pt+ bold.
func SuggestForegroundColor
func SuggestForegroundColor(bg rendering.Color, targetRatio float64) rendering.Color
SuggestForegroundColor suggests a foreground color that meets the target contrast with the given background color.
type ContrastResult
ContrastResult contains the result of a contrast check.
type ContrastResult struct {
// Ratio is the calculated contrast ratio.
Ratio float64
// MeetsAA indicates whether the ratio meets WCAG AA.
MeetsAA bool
// MeetsAAA indicates whether the ratio meets WCAG AAA.
MeetsAAA bool
}
func CheckContrast
func CheckContrast(fg, bg rendering.Color, largeText bool) ContrastResult
CheckContrast checks the contrast ratio between two colors and returns detailed results.
type LintOptions
LintOptions configures which lint rules to run.
type LintOptions struct {
// IncludeInfo includes informational messages in results.
IncludeInfo bool
// MinTouchTargetSize is the minimum touch target size in dp.
MinTouchTargetSize float64
// DisabledRules contains rules that should be skipped.
DisabledRules map[LintRule]bool
}
func DefaultLintOptions
func DefaultLintOptions() LintOptions
DefaultLintOptions returns the default lint options.
type LintResult
LintResult contains the result of a lint check.
type LintResult struct {
// NodeID is the ID of the node with the issue.
NodeID int64
// Severity indicates how serious the issue is.
Severity Severity
// Rule identifies which rule was violated.
Rule LintRule
// Message describes the issue.
Message string
// Suggestion provides guidance on how to fix the issue.
Suggestion string
}
func FilterBySeverity
func FilterBySeverity(results []LintResult, minSeverity Severity) []LintResult
FilterBySeverity returns results at or above the given severity level.
func LintSemanticsTree
func LintSemanticsTree(root *semantics.SemanticsNode) []LintResult
LintSemanticsTree runs accessibility lint checks on a semantics tree.
func LintWithOptions
func LintWithOptions(root *semantics.SemanticsNode, options LintOptions) []LintResult
LintWithOptions runs lint checks with custom options.
type LintRule
LintRule represents an accessibility lint rule.
type LintRule string
const (
// LintRuleMissingLabel indicates a node is missing an accessibility label.
LintRuleMissingLabel LintRule = "missing-label"
// LintRuleImageMissingAlt indicates an image is missing alt text.
LintRuleImageMissingAlt LintRule = "image-missing-alt"
// LintRuleTouchTargetSize indicates a touch target is too small.
LintRuleTouchTargetSize LintRule = "touch-target-size"
// LintRuleEmptyButton indicates a button has no label.
LintRuleEmptyButton LintRule = "empty-button"
// LintRuleMissingValue indicates a control is missing a value.
LintRuleMissingValue LintRule = "missing-value"
// LintRuleMissingHint indicates an interactive element is missing a hint.
LintRuleMissingHint LintRule = "missing-hint"
)
type Severity
Severity indicates the severity of a lint result.
type Severity int
const (
// SeverityInfo is for informational messages.
SeverityInfo Severity = iota
// SeverityWarning is for potential issues that should be addressed.
SeverityWarning
// SeverityError is for accessibility violations that must be fixed.
SeverityError
)
func (Severity) String
func (s Severity) String() string
String returns the severity name.
type TextSize
TextSize indicates whether text is considered "large" for WCAG purposes.
type TextSize int
const (
// TextSizeNormal is regular text (under 18pt or 14pt bold).
TextSizeNormal TextSize = iota
// TextSizeLarge is large text (18pt+ or 14pt+ bold).
TextSizeLarge
)
type WCAGLevel
WCAGLevel represents a WCAG conformance level.
type WCAGLevel int
const (
// WCAGLevelA is the minimum level of conformance.
WCAGLevelA WCAGLevel = iota
// WCAGLevelAA is the recommended level of conformance.
WCAGLevelAA
// WCAGLevelAAA is the highest level of conformance.
WCAGLevelAAA
)
func (WCAGLevel) String
func (l WCAGLevel) String() string
String returns the WCAG level name.
Generated by gomarkdoc