Soundcheck.Check.Refactor.TemporaryAssignCandidate (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 low and works with any version of Elixir.

Explanation

Flags list assigns that are only replaced whole, rendered once with :for, and never read in code. The LiveView keeps the list in memory after rendering it, though nothing reads it again until the next replacement.

Before:

def handle_event("refresh", _params, socket) do
  {:noreply, assign(socket, :log_lines, fetch_log())}
end

<p :for={line <- @log_lines}>{line}</p>

After, with a stream:

{:noreply, stream(socket, :log_lines, fetch_log(), reset: true)}

Or declare the key in temporary_assigns returned from mount/3. Keys already in temporary_assigns, keys written with update/3, assign_new/3, or assign_async/3, and keys read through socket.assigns are left out.

Confidence: low. 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.

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.