diff --git a/guides/plugins/creating_plugins.md b/guides/plugins/creating_plugins.md index 8336cd215..de789f061 100644 --- a/guides/plugins/creating_plugins.md +++ b/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 @@ -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 \ No newline at end of file +- https://hex.pm/packages/credo_demo_plugin