Soundcheck.Check.Warning.PatchWithoutHandleParams (soundcheck v0.1.0)

Copy Markdown View Source

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 push_patch, <.link patch={...}>, and JS.patch in a LiveView that defines no handle_params/3, when the path routes back to that LiveView. A patch keeps the LiveView and calls handle_params/3 with the new URL, so LiveView raises UndefinedFunctionError.

Before:

# MyAppWeb.PostLive.Index defines mount/3 and render/1 only
{:noreply, push_patch(socket, to: ~p"/posts?page=#{page}")}

After:

def handle_params(params, _uri, socket),
  do: {:noreply, assign(socket, :page, params["page"] || "1")}

Paths resolve to routes as in PatchToForeignLiveView (SC701); a patch whose routes all render another LiveView never reaches this LiveView's handle_params/3, and a path the check cannot resolve is skipped. A handle_params/3 injected by a use macro counts, because the check reads the compiled module.

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"].

:strict

Unused.

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.