Skip to content

Add Readability.SpecParameterNames check#1287

Open
johnnyt wants to merge 3 commits into
rrrene:masterfrom
johnnyt:readability-spec-parameter-names
Open

Add Readability.SpecParameterNames check#1287
johnnyt wants to merge 3 commits into
rrrene:masterfrom
johnnyt:readability-spec-parameter-names

Conversation

@johnnyt
Copy link
Copy Markdown
Contributor

@johnnyt johnnyt commented May 15, 2026

Adds a new readability check that flags @spec and @callback parameters which omit the name :: type naming syntax.

Discussed and approved in rrrene/credo-proposals#108 (default-on per maintainer preference).

Behavior

🛑 Reported:

@spec create_user(map(), String.t()) :: {:ok, User.t()}
@callback handle_event(String.t(), map(), Socket.t()) :: {:noreply, Socket.t()}

✅ Not reported:

@spec create_user(attrs :: map(), email :: String.t()) :: {:ok, User.t()}
@callback handle_event(event :: String.t(), params :: map(), socket :: Socket.t()) :: {:noreply, Socket.t()}

Handles:

  • Both @spec and @callback
  • Guard-style specs (@spec foo(x) :: x when x: term())
  • Zero-arity specs (never flagged)
  • Remote types (Module.t())
  • Multiple specs per module

Details

  • Module: Credo.Check.Readability.SpecParameterNames
  • Check ID: EX3037
  • Category: Readability
  • Priority: :low — matches the "documentation-adjacent" tier alongside checks like Readability.Specs
  • Default: enabled in .credo.exs (per maintainer steer in the proposal)
  • No params — kept minimal for an initial review; happy to add ignore_callbacks or similar if requested

Changes

  • lib/credo/check/readability/spec_parameter_names.ex — the check (~100 LOC, AST prewalk)
  • test/credo/check/readability/spec_parameter_names_test.exs — 11 tests covering the cases above
  • .credo.exs — register the check in the enabled Readability block (alphabetical)
  • CHANGELOG.md — entry under 1.7.18

Verification

  • mix test test/credo/check/readability/spec_parameter_names_test.exs — 11 tests, 0 failures
  • mix credo explain Credo.Check.Readability.SpecParameterNames renders correctly
  • The 3 pre-existing failures in MissingCheckInConfigTest / DeprecatedChecksConfigTest exist on a clean master checkout and are unrelated

Origin

I've been running an in-tree copy of this check on a Phoenix codebase for a while. Porting it upstream so other projects can benefit and so the implementation gets community review.

Closes rrrene/credo-proposals#108.

johnnyt added 3 commits May 15, 2026 13:02
Flags `@spec` and `@callback` parameters that omit the `name :: type`
naming syntax. Named typespec parameters are self-documenting and
match the idiomatic style used in the Elixir standard library, Phoenix,
and Ecto.

Discussed in rrrene/credo-proposals#108.
@rrrene
Copy link
Copy Markdown
Owner

rrrene commented May 25, 2026

Hi, I merged this on the command line, but this PR did not close automagically 🤫

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New Check: Readability.SpecParameterNames — enforce named typespec parameters

2 participants