Soundcheck.Check.Warning.UnhandledInfoMessage (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 high and works with any version of Elixir.

Explanation

Flags messages a LiveView sends to itself (send(self(), msg), Process.send/3, Process.send_after/3) that no handle_info/2 clause accepts. LiveView crashes the process on an unhandled message.

Before:

def mount(_params, _session, socket) do
  if connected?(socket), do: Process.send_after(self(), :tick, 1000)
  {:ok, socket}
end

After:

def handle_info(:tick, socket), do: {:noreply, update(socket, :now, &tick/1)}

Only literal messages are checked: an atom, or a tuple tagged with an atom ({:loaded, data} matches a {:loaded, _} clause). A handle_info(msg, socket) catch-all accepts everything. A LiveComponent runs in its parent LiveView's process, so its messages to self() are checked against every LiveView that renders it.

Handlers attached with attach_hook/4 (in the module or its on_mount hooks) make the finding unverifiable; it appears only in strict mode.

Confidence: high. Tier: semantic (run mix compile before mix credo).

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

Report unverifiable findings too.

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.