Credo Specification and Callback check

I am trying to enforce callback and Spec check through Credo. As such it is working good as a linter for our project’s needs and want to expand our usage further. My understanding is Credo.Check.Readability.Specs — Credo v1.6.4 will notify (default priority = 0) if there are specs not defined right. I did the following

  1. Added {Credo.Check.Readability.Specs, [priority: :high, exit_status: 2]} to .credo.exs bumping up the priority and making credo to fail by setting exit status to 2.
  2. Added a couple of methods exactly like in the documentation, just to see that Readability specs will catch inconsistencies in spec definition. My expectation was the check will catch the fact that spec definition for add/2 is wrong and that there is NO spec definition for add/1 . But it doesn’t report it as an issue atall. How do I go about enforcing @spec and @callback errors in Credo?

@spec add(integer, String.t) :: String.t
def add(a, b), do: a + b
def add(a), do: a + a

From the Credo docs:

The check only considers whether the specification is present, it doesn’t perform any actual type checking.

Checking the specifications for correctness is handled by Dialyzer; a good place to start for setup etc is Dialyxir.

1 Like

Thanks @al2o3cr . I also came across that. That’s why I am wondering how to use {Credo.Check.Readability.Specs, []} because at the moment I cannot get it to even check for whether a spec is provided for a. function. Curious to know if there is any further setup that I can leverage.