# `Excessibility.LiveViewRules.Rule`
[🔗](https://github.com/lessthanseventy/excessibility/blob/v0.18.1/lib/excessibility/live_view_rules/rule.ex#L1)

Behaviour for LiveView-aware accessibility rules.

Each rule inspects a parsed HTML tree (from `Floki.parse_document!/1`)
and returns zero or more findings describing accessibility issues that
axe-core cannot detect on its own — typically because the issue
depends on Phoenix-specific attributes like `phx-click`, `phx-submit`,
`phx-debounce`, etc.

Rules live under `lib/excessibility/live_view_rules/rules/` and are
auto-discovered at compile time by `Excessibility.LiveViewRules`.

## Implementing a rule

    defmodule MyApp.Rules.CustomRule do
      @behaviour Excessibility.LiveViewRules.Rule

      @impl true
      def id, do: :custom_rule

      @impl true
      def default_enabled?, do: true

      @impl true
      def check(tree, _opts) do
        tree
        |> Floki.find("div[phx-click]")
        |> Enum.map(&build_finding/1)
      end

      defp build_finding(element), do: %{...}
    end

Register custom rules via application config:

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

# `finding`

```elixir
@type finding() :: %{
  rule: atom(),
  severity: severity(),
  message: String.t(),
  element: String.t(),
  selector: String.t(),
  help: String.t(),
  help_url: String.t() | nil
}
```

A single finding from a LiveView rule.

# `severity`

```elixir
@type severity() :: :critical | :serious | :moderate | :minor
```

Severity levels for LiveView rule findings.

# `check`

```elixir
@callback check(tree :: Floki.html_tree(), opts :: keyword()) :: [finding()]
```

Inspects the parsed HTML tree and returns any findings.

`opts` is passed through from `Excessibility.LiveViewRules.scan/2` so
rules can accept rule-specific options if needed.

# `default_enabled?`

```elixir
@callback default_enabled?() :: boolean()
```

Whether the rule runs by default. Can be overridden via config.

# `id`

```elixir
@callback id() :: atom()
```

The unique identifier for this rule.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
