Share Config Between Codebases
Sharing configuration between codebases using public config repos
To standardize Trunk configuration across an organization, you can create and publish a public plugins repository. This repo can define new linter definitions, specify enabled linters and actions, and even export linter configs.
Once you've created your plugin repository, you can source it in other repositories to adopt shared configuration across your organization. For an example of how we do this in our own org, check out our configs repo.
Note that in order to keep linters and tools up to date in your plugin configs repo, you'll need to run trunk upgrade --apply-to=plugin.yaml
to apply upgrades. After making a public GitHub release with your plugin changes, other dependent repos will pick up these changes automatically when running trunk upgrade
.
Get started
Let's walk through how to create a simple linter that warns about TODOs in your codebase.
We'll start by creating a new Git repository:
And then create a linter that can find TODOs in your codebase using grep
and sed
:
Now we can turn this linter on in a repository where we have trunk
set up:
And now, to demonstrate how this works, let's trunk check
some files where we know we have TODOs:
which will show you something like this:
Organizing your code
In the example we gave above, we put the linter's source code in plugin.yaml
, which is fine for an example, but not really great for anything more than that. We can take the sed
command from the plugin we created earlier and push that into the shell script:
Tip: Remember to run
chmod u+x todo-finder-parser.sh
so thattrunk
can run it!
and also point the definition of todo-finder
at it:
We can also go another step and push the entire linter definition into a shell script:
See our documentation on custom linters and custom parsers for more on what you can do, such as writing your parser in Javascript or Python!
Publishing your plugin
To share your plugin with the world, all you have to do is tag a release and push it to GitHub, Gitlab, or some other repository hosting service:
Now that it's available on the Internet, everyone else can just use your plugin by running:
Last updated