MetaCredo.Config (MetaCredo v0.6.2)

View Source

Parses and manages .metacredo.exs configuration files.

Configuration follows a map structure similar to .credo.exs:

%{
  configs: [
    %{
      name: "default",
      files: %{
        included: ["lib/", "src/", "web/"],
        excluded: [
          ~r"(^|/)_build/",
          ~r"(^|/)deps/",
          ~r"(^|/)node_modules/"
        ]
      },
      checks: %{
        enabled: [
          {MetaCredo.Check.Security.HardcodedValue, [exclude_localhost: true]},
          {MetaCredo.Check.Warning.MissingErrorHandling, []},
          {MetaCredo.Check.Readability.MagicNumber, [ignored_numbers: [0, 1, -1, 2]]}
        ],
        disabled: [
          {MetaCredo.Check.Readability.ModuleDoc, []}
        ]
      }
    }
  ]
}

Configuration files are resolved in order from .metacredo.exs or config/.metacredo.exs. Run mix metacredo.gen.config to generate a complete configuration file listing all checks.

Summary

Functions

Returns the default configuration.

Returns the path to the default configuration file.

Returns default disabled checks.

Returns the list of enabled checks from config.

Returns the file patterns from config.

Returns the path to the global user configuration file.

Reads and parses the configuration file, falling back to defaults.

Types

config()

@type config() :: %{
  name: String.t(),
  no_db: boolean(),
  no_user: boolean(),
  files: %{included: [String.t()], excluded: [String.t() | Regex.t()]},
  checks: %{
    enabled: [{module(), Keyword.t()}] | :all,
    disabled: [{module(), Keyword.t()}]
  }
}

Functions

default()

@spec default() :: config()

Returns the default configuration.

default_config_path()

@spec default_config_path() :: String.t()

Returns the path to the default configuration file.

default_disabled_checks()

@spec default_disabled_checks() :: [module()]

Returns default disabled checks.

enabled_checks(map)

@spec enabled_checks(config()) :: [{module(), Keyword.t()}]

Returns the list of enabled checks from config.

file_patterns(map)

@spec file_patterns(config()) :: %{included: [String.t()], excluded: [term()]}

Returns the file patterns from config.

global_config_path()

@spec global_config_path() :: String.t()

Returns the path to the global user configuration file.

read(config_file \\ nil)

@spec read(String.t() | nil) :: config()

Reads and parses the configuration file, falling back to defaults.