Using Plugins

Installing plugins

Plugins are just modules.

Plugins can be included by listing them under the :plugins field .credo.exs:

%{
  configs: [
    %{
      name: "default",
      plugins: [
        {CredoDemoPlugin, []}
      ]
    }
  ]
}

Most of the time, a Credo plugin will be published on Hex. You include it as a dependency in mix.exs like any other dependency:

{:credo_demo_plugin, "~> 0.1.0"},

Plugins, like checks, are just modules and functions. They are enabled in Credo's configuration file .credo.exs, which you can generate via mix credo gen.config:

$ mix credo gen.config
* creating .credo.exs

The demo plugin adds a command called "demo":

$ mix credo demo
By the power of !

It seems like there's something missing before the ! ...

Configuring plugins

Plugins can be configured via params, just like checks.

Each entry consists of a two-element tuple: the plugin's module and a keyword list of parameters, which can be used to configure the plugin itself.

%{
  configs: [
    %{
      name: "default",
      plugins: [
        {CredoDemoPlugin, [castle: "Grayskull"]}
      ]
    }
  ]
}
$ mix credo demo
By the power of Grayskull!

Just in case, Plugins can be deactivated by setting the second tuple element to false.

%{
  configs: [
    %{
      name: "default",
      plugins: [
        {CredoDemoPlugin, false} # <-- don't load this for now
      ]
    }
  ]
}

The demo plugin used in the docs can be found on GitHub and Hex: