axe

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package axe provides accessibility testing using axe-core.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Evaluator

type Evaluator interface {
	Evaluate(ctx context.Context, script string) (interface{}, error)
}

Evaluator is the interface for JavaScript evaluation.

type Impact

type Impact string

Impact represents the severity of an accessibility violation.

const (
	ImpactCritical Impact = "critical"
	ImpactSerious  Impact = "serious"
	ImpactModerate Impact = "moderate"
	ImpactMinor    Impact = "minor"
)

type Node

type Node struct {
	HTML           string   `json:"html"`
	Target         []string `json:"target"`
	FailureSummary string   `json:"failureSummary,omitempty"`
	Impact         Impact   `json:"impact,omitempty"`
}

Node represents a DOM element that violated or passed a rule.

type Options

type Options struct {
	// Standard is the WCAG standard to check against.
	Standard Standard

	// IncludeSelector limits checking to elements matching this selector.
	IncludeSelector string

	// ExcludeSelector excludes elements matching this selector.
	ExcludeSelector string

	// Rules specifies which rules to run.
	Rules []string

	// DisabledRules specifies rules to skip.
	DisabledRules []string

	// FailOn specifies which impact levels cause failure.
	// Default is "serious" (fails on critical and serious).
	FailOn Impact
}

Options configures accessibility checking.

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions returns sensible defaults for WCAG 2.2 AA.

type Result

type Result struct {
	Violations      []Violation     `json:"violations"`
	Passes          []RuleResult    `json:"passes"`
	Incomplete      []RuleResult    `json:"incomplete"`
	Inapplicable    []RuleResult    `json:"inapplicable"`
	URL             string          `json:"url"`
	Timestamp       string          `json:"timestamp"`
	TestEngine      TestEngine      `json:"testEngine"`
	TestRunner      TestRunner      `json:"testRunner"`
	TestEnvironment TestEnvironment `json:"testEnvironment"`
}

Result contains the accessibility check results.

func Check

func Check(ctx context.Context, evaluator Evaluator, opts *Options) (*Result, error)

Check runs accessibility checks against the current page.

func (*Result) FilterViolations

func (r *Result) FilterViolations(failOn Impact) []Violation

FilterViolations returns violations at or above the specified impact level.

func (*Result) HasFailures

func (r *Result) HasFailures(failOn Impact) bool

HasFailures checks if the result has violations at or above the specified impact level.

func (*Result) SaveReport

func (r *Result) SaveReport(filename string) error

SaveReport saves the full results to a JSON file.

func (*Result) Summary

func (r *Result) Summary() string

Summary returns a human-readable summary of the results.

type RuleResult

type RuleResult struct {
	ID          string   `json:"id"`
	Impact      Impact   `json:"impact,omitempty"`
	Tags        []string `json:"tags"`
	Description string   `json:"description"`
	Help        string   `json:"help"`
	HelpURL     string   `json:"helpUrl"`
	Nodes       []Node   `json:"nodes"`
}

RuleResult represents an axe-core rule result (for passes, incomplete, inapplicable).

type Standard

type Standard string

Standard represents a WCAG accessibility standard.

const (
	WCAG2A    Standard = "wcag2a"
	WCAG2AA   Standard = "wcag2aa"
	WCAG2AAA  Standard = "wcag2aaa"
	WCAG21A   Standard = "wcag21a"
	WCAG21AA  Standard = "wcag21aa"
	WCAG21AAA Standard = "wcag21aaa"
	WCAG22AA  Standard = "wcag22aa"
)

type TestEngine

type TestEngine struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

TestEngine contains axe-core version info.

type TestEnvironment

type TestEnvironment struct {
	UserAgent    string `json:"userAgent"`
	WindowWidth  int    `json:"windowWidth"`
	WindowHeight int    `json:"windowHeight"`
}

TestEnvironment contains browser info.

type TestRunner

type TestRunner struct {
	Name string `json:"name"`
}

TestRunner contains runner info.

type Violation

type Violation struct {
	ID          string   `json:"id"`
	Impact      Impact   `json:"impact"`
	Tags        []string `json:"tags"`
	Description string   `json:"description"`
	Help        string   `json:"help"`
	HelpURL     string   `json:"helpUrl"`
	Nodes       []Node   `json:"nodes"`
}

Violation represents an accessibility violation.

Jump to

Keyboard shortcuts

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