validation

package
v0.23.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Rendered for darwin/amd64

Overview

Package validation provides accessibility validation and linting tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContrastRatio

func ContrastRatio(fg, bg graphics.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 graphics.Color, targetRatio float64) graphics.Color

SuggestForegroundColor suggests a foreground color that meets the target contrast with the given background color.

Types

type ContrastResult

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
}

ContrastResult contains the result of a contrast check.

func CheckContrast

func CheckContrast(fg, bg graphics.Color, largeText bool) ContrastResult

CheckContrast checks the contrast ratio between two colors and returns detailed results.

type LintOptions

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
}

LintOptions configures which lint rules to run.

func DefaultLintOptions

func DefaultLintOptions() LintOptions

DefaultLintOptions returns the default lint options.

type LintResult

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
}

LintResult contains the result of a lint check.

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

type LintRule string

LintRule represents an accessibility lint rule.

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

type Severity int

Severity indicates the severity of a lint result.

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

type TextSize int

TextSize indicates whether text is considered "large" for WCAG purposes.

const (
	// TextSizeNormal is regular text (under 18pt or 14pt bold).
	TextSizeNormal TextSize = iota

	// TextSizeLarge is large text (18pt+ or 14pt+ bold).
	TextSizeLarge
)

type WCAGLevel

type WCAGLevel int

WCAGLevel represents a WCAG conformance level.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL