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

Explanation

Flags variables a template binds with <% name = ... %> and reads afterwards. LiveView cannot track a template-local variable, so every expression that reads it re-renders on every change. LiveView warns only about variables bound outside the template.

Before:

<% total = Enum.sum(@prices) %>
<p>Total: {total}</p>

After:

def mount(_params, _session, socket),
  do: {:ok, assign(socket, prices: prices, total: Enum.sum(prices))}

<p>Total: {@total}</p>

Variables bound by :for, :let, and EEx for/case clauses are tracked by LiveView and never reported.

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.

General Parameters

Like with all checks, general params can be applied.

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