Add Readability.SpecParameterNames check#1287
Open
johnnyt wants to merge 3 commits into
Open
Conversation
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.
Owner
|
Hi, I merged this on the command line, but this PR did not close automagically 🤫 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a new readability check that flags
@specand@callbackparameters which omit thename :: typenaming syntax.Discussed and approved in rrrene/credo-proposals#108 (default-on per maintainer preference).
Behavior
🛑 Reported:
✅ Not reported:
Handles:
@specand@callback@spec foo(x) :: x when x: term())Module.t())Details
Credo.Check.Readability.SpecParameterNamesEX3037:low— matches the "documentation-adjacent" tier alongside checks likeReadability.Specs.credo.exs(per maintainer steer in the proposal)ignore_callbacksor similar if requestedChanges
lib/credo/check/readability/spec_parameter_names.ex— the check (~100 LOC, ASTprewalk)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.18Verification
mix test test/credo/check/readability/spec_parameter_names_test.exs— 11 tests, 0 failuresmix credo explain Credo.Check.Readability.SpecParameterNamesrenders correctlyMissingCheckInConfigTest/DeprecatedChecksConfigTestexist on a cleanmastercheckout and are unrelatedOrigin
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.