Basics
This check is disabled by default.
Learn how to enable it via .credo.exs.
This check has a base priority of normal and works with any version of Elixir.
Explanation
Flags phx-click and phx-click-away events whose payload lacks a
key that every matching handle_event/3 clause requires. No clause
matches the params, so the click raises FunctionClauseError.
Before:
<button phx-click="delete">Delete</button>
def handle_event("delete", %{"id" => id}, socket)After:
<button phx-click="delete" phx-value-id={post.id}>Delete</button>A click sends the element's phx-value-* attributes, its value
when the element has one, and the value: map of a JS.push.
Browsers lowercase attribute names, so phx-value-postId arrives as
"postid". The check reads the receivers' compiled clauses, so it
routes events as UnhandledEvent (SC101) does and skips events no
clause names. It stays silent when an element spreads attributes
({@rest}), when a JS.push value is not a literal map, and for
receivers whose handlers attach_hook/4 can intercept. Function
component calls count as sending value, since the rendered element
may carry one. List keys that a LiveSocket metadata callback adds
to click events in metadata_keys.
Confidence: medium. 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"].
:strict
Unused.
This parameter defaults to false.
:metadata_keys
Keys that LiveSocket metadata callbacks add to every click.
This parameter defaults to [].
General Parameters
Like with all checks, general params can be applied.
Parameters can be configured via the .credo.exs config file.