Skip to main content

W0082 - Prefer term() over any()

Warning

-module(main).

-spec lookup(key()) -> any().
%% ^^^ 💡 warning: Prefer `term()` over `any()`.
lookup(Key) ->
do_lookup(Key).

Explanation

This diagnostic fires on uses of the any() type, in any type position: -spec, -type, -opaque, -callback, and -record field types.

any() and term() name the same type — the set of all Erlang terms — but a codebase benefits from standardising on one of the two spellings, so that a reader never has to wonder whether they mean something different.

Prefer the most specific type you can write. When a value really can be any term, spell that term().

Since picking a spelling is a matter of convention, this diagnostic is disabled by default. It can be enabled by adding the following to the .elp_lint.toml file for your project:

[linters.avoid_any_type]
enabled = true

Fix

Replace any() with term(), or — better — with the specific type the value actually has. A quick-fix is offered for the mechanical any()term() replacement.