AshCredo.Check.Warning.UnknownAction (ash_credo v0.12.1)

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 raw Ash.* API calls that reference an action that does not exist on the resolved resource. Catches typos at lint time:

Ash.read!(MyApp.Post, action: :publishd)
#                             ^^^^^^^^ - no such action
# Did you mean `:published`?

The check uses Ash's runtime introspection (Ash.Resource.Info.actions/1) to read the resource's fully-resolved action list, then jaro-distance to suggest the closest known action name when one is similar enough.

Unlike Refactor.UseCodeInterface, this check is objective: the action either exists on the resource or it doesn't. There's nothing to configure.

It runs against the same call sites that UseCodeInterface does - Ash.read!/Ash.get!/Ash.bulk_*/Ash.Changeset.for_*/ Ash.Query.for_read/Ash.ActionInput.for_action - whenever both the resource and the action argument are literal values that can be resolved at lint time.

Requirements

Your project must be compiled before running mix credo. If Ash is not available in the VM running Credo, the check is a no-op and emits a single diagnostic.

Check-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.