Skip to content

Commit

Permalink
Add docs about referencing local plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
rrrene committed Mar 5, 2024
1 parent ec026f6 commit a095c30
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions guides/plugins/creating_plugins.md
@@ -1,6 +1,8 @@
# Creating Plugins

A plugin is basically just a module that provides an `init/1` callback, taking a `Credo.Execution` struct as its only parameter.
## Basics

A plugin is basically just a module that provides an `init/1` callback, taking a `Credo.Execution` struct as its only parameter and returning a `Credo.Execution`. That's basically it.

```elixir
defmodule CredoDemoPlugin do
Expand Down Expand Up @@ -40,7 +42,43 @@ You can find more information on `Credo.Plugin` and the functions imported:
- `Credo.Plugin.prepend_task/3`
- `Credo.Plugin.prepend_task/4`

## Development

Plugins are generally developed by putting them in a Hex package, referencing that package in `mix.exs` and then configuring the plugin in `.credo.exs`.

However, for local development it can be beneficial to develop a plugin inside a project.
But referencing modules from the current Mix project in `.credo.exs` does not work out of the box, because the project is not loaded for every `mix` task.

To be able to use a module from the current project in `.credo.exs`, run `mix app.config` first:

```bash
mix do app.config + credo
```

This way, local plugins can be referenced in `.credo.exs`.

Another, even more pragmatic way to do it is to run `app.config` from `.credo.exs` directly (since it is just a script file):

```elixir
Mix.Task.run("app.config", [])

%{
configs: [
%{
name: "default",
plugins: [
{MyProject.CredoPlugin, []}
]
}
]
}
```

This should naturally taken with a grain of salt, e.g. taking steps that this is only active during development.

## Further reading

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

- https://github.com/rrrene/credo_demo_plugin
- https://hex.pm/packages/credo_demo_plugin
- https://hex.pm/packages/credo_demo_plugin

0 comments on commit a095c30

Please sign in to comment.