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
Flags template events that no handle_event/3 clause in the receiving
LiveView or LiveComponent accepts. LiveView crashes the process when
such an event arrives.
Before:
<button phx-click="sav">Save</button>
def handle_event("save", params, socket), do: ...After:
<button phx-click="save">Save</button>The check follows LiveView's routing. Without phx-target, an event
goes to the LiveView that renders the element, also from inside a
LiveComponent or a function component (every LiveView that renders
the component must handle it). With phx-target={@myself}, it goes
to the LiveComponent that renders the element. JS.push events and
their target: option follow the same rules.
A finding is unverifiable, and appears only in strict mode, when the
event name or target is dynamic, the target is a CSS selector, the
template has no known render path, or the receiver attaches handlers
with attach_hook/4. The message suggests the closest handled event
within a few edits.
A shared component may render an event only for some of its callers.
When the event sits inside conditions soundcheck cannot evaluate
(:if={@actor.type != :service_account}) and another receiver
handles it, the finding is unverifiable (guarded): the condition
may keep the event from rendering where it is unhandled. To have
soundcheck verify such a component, guard the event with a boolean
attr the callers pass as a literal:
attr :show_admin_actions, :boolean, default: false
<button :if={@show_admin_actions} phx-click="promote">Promote</button>
<.member_panel show_admin_actions={true} />A call site that passes false, or omits the attr, rules the event
out for its LiveView.
Confidence: high. Tier: semantic (run mix compile before mix credo).
Check-Specific Parameters
Use the following parameters to configure this check:
:excluded_paths
Paths to skip (atoms, binaries as path segments, or regexes).
This parameter defaults to [~r/\/test\//, "test"].
:ignore_events
Event names to skip: binaries or regexes.
This parameter defaults to [].
:strict
Report unverifiable findings too.
This parameter defaults to false.
General Parameters
Like with all checks, general params can be applied.
Parameters can be configured via the .credo.exs config file.