W0091: Missing Function Specification
Error
-module(example).
-export([foo/1]).
foo(Value) -> {ok, Value + 1}.
%% ^^^ error: W0091: Missing specification for function foo/1
Explanation
All exported and internal functions are required to have a -spec, so type
checkers like eqwalizer can give better results.
The compiler's warn_missing_spec checks exported functions, while
warn_missing_spec_all also checks internal functions. This diagnostic checks
both, but exempts Common Test callbacks and known testcases rather than skipping
suites entirely.
Unlike W0012, which checks compiler pragmas and skips test files, W0091 checks specs directly, exempting only CT callbacks and known testcases.
Add the function's contract:
-spec foo(Value) -> {ok, integer()} when Value :: integer().
foo(Value) -> {ok, Value + 1}.
Common Test Suites
In recognised suites, exported Common Test callbacks, known runnable testcases,
and their exported /0 information functions are exempt. All other exported and
internal functions still need specs.
Configuration
This diagnostic is disabled by default in the editor and CLI. To opt in, add this to the lint configuration:
[linters.missing_function_spec]
enabled = true
severity = "error"