Soundcheck.Check.Design.UnusedEventHandler (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 literal handle_event/3 clauses that no template, JS.push, or hook in the project emits to their module: dead code left behind after a template change.

Before:

<button phx-click="save">Save</button>

def handle_event("save", params, socket), do: ...
def handle_event("archive", params, socket), do: ...  # nothing emits it

After: remove the "archive" clause, or wire up its emitter.

The check needs a closed world to be right, so it reports nothing unless every event emitter in the project resolves: one dynamic event name (phx-click={@action}), selector target, unresolvable hook push, or pushEvent with a dynamic name anywhere in the project's JavaScript turns it off. A handler whose event name appears as a string anywhere else in the project's Elixir code (helpers, tests), or as a literal pushEvent name in its JavaScript, is never reported.

Confidence: medium. 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.

:ignore_events

Event names to skip: binaries or regexes.

This parameter defaults to [].

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.