Basics
This check is disabled by default.
Learn how to enable it via .credo.exs.
This check has a base priority of high and works with any version of Elixir.
Explanation
Flags upload names a LiveView or LiveComponent uses but never allows.
@uploads holds only the uploads allow_upload/3 registered, so a
template reading @uploads.photo when the module allows :avatar
raises KeyError on render, and consume_uploaded_entries/3,
uploaded_entries/2, cancel_upload/3, or disallow_upload/2 on an
unknown name raises ArgumentError.
Before:
def mount(_params, _session, socket),
do: {:ok, allow_upload(socket, :avatar, accept: ~w(.jpg .png))}
<.live_file_input upload={@uploads.photo} />After:
<.live_file_input upload={@uploads.avatar} />Definitions are allow_upload/3 calls with a literal atom name in the
module's own functions and in the project functions it calls, through
remote calls and imports at any depth. Reads come from its render/1
template, colocated or inline. The check skips a module when it and
those functions allow no upload, when any of them names one
dynamically, or when it passes its socket to a function outside the
project and Phoenix, since that function may allow uploads the check
cannot see.
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.