Rbtz. CredoChecks. Warning. PushEventSocketBinding
(rbtz_credo_checks v0.3.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
Requires the result of push_event/3 to be reassigned to socket
rather than discarded as a statement.
push_event/3 returns a new socket with the queued event attached. If
the return value is thrown away, the event never reaches the client —
the call silently no-ops. The fix is always to rebind: socket = push_event(socket, ...) or to chain the call onto a pipe that
propagates the socket.
The check fires on push_event calls that appear as a non-final
statement in a block, with their return value discarded. Pipes ending
in push_event (socket |> push_event(...)) are flagged the same
way; pipes that continue past push_event to another stage
(socket |> push_event(...) |> other()) are not, because the
downstream stage may or may not preserve the event — we can't tell.
Bad
def handle_event("save", _, socket) do
push_event(socket, "saved", %{})
{:noreply, socket}
endGood
def handle_event("save", _, socket) do
socket = push_event(socket, "saved", %{})
{:noreply, socket}
endCheck-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.