Bylaw.Credo.Check.Elixir.FullyTypedOpts (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 high and works with any version of Elixir.

Explanation

Fully type option lists instead of using keyword() or Keyword.t() for opts parameters or *_opts type aliases.

Examples

Avoid:

  @spec search(query :: String.t(), opts :: keyword()) :: result()
  @type search_opts :: Keyword.t()

Prefer:

  @type search_opt ::
          {:max_results, pos_integer()}
          | {:country, String.t()}

  @type search_opts :: [search_opt()]

  @spec search(query :: String.t(), opts :: search_opts()) :: result()

Notes

Path exclusions are matched against the source filename and are intended for generated files or temporary migration areas.

The check uses static AST analysis, so dynamic code generation and macro-expanded code may fall outside its signal.

Options

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

%{
  configs: [
    %{
      name: "default",
      checks: [
        {Bylaw.Credo.Check.Elixir.FullyTypedOpts,
         [
           excluded_paths: ["test/support/"]
         ]}
      ]
    }
  ]
}
  • :excluded_paths - List of path prefixes or regexes to exclude from this check.

Usage

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

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

Check-Specific Parameters

Use the following parameters to configure this check:

:excluded_paths

List of path prefixes or regexes to exclude from this check.

This parameter defaults to [].

General Parameters

Like with all checks, general params can be applied.

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