Soundcheck.Check.Refactor.FormForChangeset (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 forms built directly from a changeset assign (<.form for={@changeset}>) instead of from to_form/2. A changeset assign changes as a whole on every validation, so LiveView re-renders the entire form; a Phoenix.HTML.Form from to_form/2 lets it track fields individually, and is what Phoenix's generators and <.input> expect.

Before:

assign(socket, :changeset, Accounts.change_user(user))

<.form for={@changeset} phx-change="validate">

After:

assign(socket, :form, to_form(Accounts.change_user(user)))

<.form for={@form} phx-change="validate">

The check recognizes a changeset by name: an assign whose name ends in changeset.

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.