Excessibility.LiveViewRules (Excessibility v0.14.0)

View Source

LiveView-aware accessibility rules.

Runs a set of HTML-level checks that axe-core cannot perform because they depend on Phoenix-specific attributes (phx-click, phx-submit, phx-debounce, etc.). These rules complement axe-core rather than replace it — snapshot tests run both axe-core and these rules.

On non-Phoenix HTML the rules are no-ops: if no phx-* attributes exist, no findings are produced.

Usage

{:ok, html} = File.read("snapshot.html")
result = Excessibility.LiveViewRules.scan(html)

for finding <- result.findings do
  IO.puts("[#{finding.severity}] #{finding.rule}: #{finding.message}")
end

Options

  • :disable — list of rule ids to skip (default [])
  • :only — if given, run only these rule ids (overrides :disable)

Adding custom rules

Register application-level rule modules via config:

config :excessibility, custom_live_view_rules: [MyApp.Rules.CustomRule]

See Excessibility.LiveViewRules.Rule for the behaviour.

Summary

Types

The aggregate result of a LiveView rule scan.

Functions

Returns all registered rule modules (built-in + custom via config).

Scan an HTML string and return findings from all enabled rules.

Like scan/2, but reads HTML from a file path.

Types

result()

@type result() :: %{
  findings: [Excessibility.LiveViewRules.Rule.finding()],
  rules_run: [atom()]
}

The aggregate result of a LiveView rule scan.

Functions

rules()

@spec rules() :: [module()]

Returns all registered rule modules (built-in + custom via config).

scan(html, opts \\ [])

@spec scan(
  String.t(),
  keyword()
) :: result()

Scan an HTML string and return findings from all enabled rules.

Returns %{findings: [...], rules_run: [rule_id, ...]}. On a parse failure returns %{findings: [], rules_run: []}.

scan_file(path, opts \\ [])

@spec scan_file(
  Path.t(),
  keyword()
) :: result()

Like scan/2, but reads HTML from a file path.