Skip to content

Commit a095c30

Browse files
committed
Add docs about referencing local plugins
1 parent ec026f6 commit a095c30

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

guides/plugins/creating_plugins.md

+40-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Creating Plugins
22

3-
A plugin is basically just a module that provides an `init/1` callback, taking a `Credo.Execution` struct as its only parameter.
3+
## Basics
4+
5+
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.
46

57
```elixir
68
defmodule CredoDemoPlugin do
@@ -40,7 +42,43 @@ You can find more information on `Credo.Plugin` and the functions imported:
4042
- `Credo.Plugin.prepend_task/3`
4143
- `Credo.Plugin.prepend_task/4`
4244

45+
## Development
46+
47+
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`.
48+
49+
However, for local development it can be beneficial to develop a plugin inside a project.
50+
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.
51+
52+
To be able to use a module from the current project in `.credo.exs`, run `mix app.config` first:
53+
54+
```bash
55+
mix do app.config + credo
56+
```
57+
58+
This way, local plugins can be referenced in `.credo.exs`.
59+
60+
Another, even more pragmatic way to do it is to run `app.config` from `.credo.exs` directly (since it is just a script file):
61+
62+
```elixir
63+
Mix.Task.run("app.config", [])
64+
65+
%{
66+
configs: [
67+
%{
68+
name: "default",
69+
plugins: [
70+
{MyProject.CredoPlugin, []}
71+
]
72+
}
73+
]
74+
}
75+
```
76+
77+
This should naturally taken with a grain of salt, e.g. taking steps that this is only active during development.
78+
79+
## Further reading
80+
4381
The demo plugin used in the docs can be found on GitHub and Hex:
4482

4583
- https://github.com/rrrene/credo_demo_plugin
46-
- https://hex.pm/packages/credo_demo_plugin
84+
- https://hex.pm/packages/credo_demo_plugin

0 commit comments

Comments
 (0)