Basics
This check is disabled by default.
Learn how to enable it via .credo.exs.
This check has a base priority of high and works with any version of Elixir.
Explanation
Requires every element with phx-hook to also carry an id attribute.
Phoenix LiveView hooks are keyed by DOM id: without it, LiveView
cannot route pushEvents back to the right hook instance, and morphdom
may swap the hooked element with a different one across patches —
causing mounted() to be called repeatedly or never. The framework
itself raises at runtime if you forget the id, but a static check
catches the typo at code-review time instead.
The check inspects every ~H sigil and every .heex template referenced
via embed_templates. It walks each opening tag (across multiple lines)
and flags those that carry phx-hook= without id=.
Bad
<div phx-hook=".PhoneNumber">...</div>Good
<div id="phone-number" phx-hook=".PhoneNumber">...</div>Check-Specific Parameters
There are no specific parameters for this check.
General Parameters
Like with all checks, general params can be applied.
Parameters can be configured via the .credo.exs config file.