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
Do not use any() or term() in typespecs.
Why
any() and term() tell Dialyzer that every value is acceptable.
That makes the spec look documented while removing much of the
protection the spec was supposed to provide. Agents often reach for
these broad types when they do not know the real shape yet.
Bad
@spec decode(binary()) :: term()
@spec publish(any()) :: :ok | {:error, term()}
@type payload :: %{optional(atom()) => any()}Good
@type payload :: %{
required(:id) => String.t(),
optional(:metadata) => map()
}
@type publish_error :: :missing_topic | {:invalid_payload, payload()}
@spec decode(binary()) :: {:ok, payload()} | {:error, :invalid_json}
@spec publish(payload()) :: :ok | {:error, publish_error()}Use a named type, struct, tagged tuple, union, or a real type variable that preserves a relationship between input and output.
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.