Basics
This check is disabled by default.
Learn how to enable it via .credo.exs.
This check has a base priority of low and works with any version of Elixir.
Explanation
Flags assign keys a LiveView or LiveComponent sets but never reads:
not in its templates, not in any layout, and not through
socket.assigns in its code. Every assign lives in the process and
goes through change tracking for nothing.
Before:
def mount(_params, _session, socket) do
{:ok, assign(socket, posts: list_posts(), page_size: 20)}
end
# no template or callback reads @page_sizeAfter:
def mount(_params, _session, socket) do
{:ok, assign(socket, posts: list_posts())}
endOnly literal keys count. When code passes the assigns map along whole
(helper(socket.assigns), <.panel {assigns} />), any key could be
read there, and the check skips the module. Keys read only by an
on_mount hook or a parent are reported; list them in
ignore_assigns.
Confidence: medium. Tier: syntactic (works without compiling).
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.
:ignore_assigns
Keys never reported (atoms).
This parameter defaults to [:page_title].
General Parameters
Like with all checks, general params can be applied.
Parameters can be configured via the .credo.exs config file.