Bylaw.Credo.Check.Elixir.NamedSpecParams (bylaw_credo v0.1.0-alpha.1)

Copy Markdown View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

This check has a base priority of normal and works with any version of Elixir.

Explanation

Requires named parameters in all @spec declarations.

Examples

Avoid: Positional-only types omit what each argument represents:

  @spec fetch(UUIDv7.t(), integer()) :: {:ok, Run.t()} | {:error, term()}
  @spec submit(UUIDv7.t(), UUIDv7.t(), UUIDv7.t(), UUIDv7.t(), list(map())) :: :ok

Prefer: Give each parameter a name so the spec is self-documenting:

  @spec fetch(run_id :: UUIDv7.t(), limit :: integer()) :: {:ok, Run.t()} | {:error, term()}
  @spec submit(
          tenant_id :: UUIDv7.t(),
          workspace_id :: UUIDv7.t(),
          run_id :: UUIDv7.t(),
          message_id :: UUIDv7.t(),
          tool_results :: list(map())
        ) :: :ok

Notes

This check uses static AST analysis, so it favors clear source-level patterns over runtime behavior.

Options

Configure options in .credo.exs with the check tuple:

%{
  configs: [
    %{
      name: "default",
      checks: [
        {Bylaw.Credo.Check.Elixir.NamedSpecParams,
         [
           min_params: 2
         ]}
      ]
    }
  ]
}
  • :min_params - Minimum number of parameters to trigger the check (default: 1).

Usage

Add this check to Credo's checks: list in .credo.exs:

%{
  configs: [
    %{
      name: "default",
      checks: [
        {Bylaw.Credo.Check.Elixir.NamedSpecParams, []}
      ]
    }
  ]
}

Check-Specific Parameters

Use the following parameters to configure this check:

:min_params

Minimum number of parameters to trigger the check (default: 1).

This parameter defaults to 1.

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.