Bylaw.Credo.Check.PhoenixLiveView.NoInlineAssignInReturnTuple
(bylaw_credo v0.1.0-alpha.1)
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 higher and works with any version of Elixir.
Explanation
Extract LiveView assign/2,3 and assign_new/3 calls before returning
the socket tuple.
Examples
Avoid:
{:noreply, assign(socket, :user, user)}
{:ok, socket |> assign(:user, user)}Prefer:
socket = assign(socket, :user, user)
{:noreply, socket}Notes
Inline assignment hides the socket transformation inside the return value. That makes it harder to add more socket changes, inspect intermediate values, or keep return tuples visually consistent.
Keep socket updates in normal expressions and reserve {:ok, socket},
{:noreply, socket}, and {:reply, reply, socket} for returning the
final socket.
This check uses static AST analysis, so it favors clear source-level patterns over runtime behavior.
Options
This check has no check-specific options. Configure it with an empty option list.
Usage
Add this check to Credo's checks: list in .credo.exs:
%{
configs: [
%{
name: "default",
checks: [
{Bylaw.Credo.Check.PhoenixLiveView.NoInlineAssignInReturnTuple, []}
]
}
]
}Check-Specific Parameters
There are no specific parameters for this check.
General Parameters
Like with all checks, general params can be applied.
Parameters can be configured via the .credo.exs config file.