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 LiveViews that subscribe to PubSub in mount/3 but define no
handle_info/2 at all. The first broadcast on the topic crashes the
LiveView.
Before:
def mount(_params, _session, socket) do
if connected?(socket), do: Phoenix.PubSub.subscribe(MyApp.PubSub, "posts")
{:ok, socket}
endAfter:
def handle_info({:post_created, post}, socket),
do: {:noreply, stream_insert(socket, :posts, post)}Subscriptions match subscribe_functions by alias-expanded name, as
in UnguardedSubscribe. A handle_info/2 injected by a use macro
counts, because the check reads the compiled module; a handler
attached with attach_hook/4 silences it.
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
Unused.
This parameter defaults to false.
:subscribe_functions
Regexes or exact names of subscribing functions, as Module.function.
This parameter defaults to [~r/^Phoenix\.PubSub\.subscribe$/, ~r/\.subscribe$/].
General Parameters
Like with all checks, general params can be applied.
Parameters can be configured via the .credo.exs config file.