Initialize Trunk
Before you can start using Trunk Code Quality, you need to install and initialize Trunk in your repo. This page covers the initialization process.
Install the CLI
The Trunk CLI can be installed in many different ways depending on your use case.
We recommend installing the CLI via NPM if you’re already using NPM, or using cURL and committing the launcher to Git for all other projects. Both methods allow your teammates to use Trunk without needing an additional install step.
Using NPM
If your project uses a package.json
, you can specify the Trunk Launcher as a dependency so your developers can start using Trunk after installing Node dependencies.
Then add Trunk Launcher in your package.json
as a script:
Using cURL
You can install the Trunk Launcher script directly by downloading it through cURL. The launcher script supports both macOS and Linux environments.
To allow your teammates to use trunk
without installing anything, the launcher can be committed directly into your repo:
When the launcher is called for the first time by your teammates, the Trunk Launcher will download, manage, and run the appropriate binary for the environment.
Other Environments
Initializing Trunk
Before you can use Trunk, you need to initialize Trunk in your repo. Initializing Trunk will generate the necessary config files, recommend linters based on your project files, and configure githooks.
NPM installs
If you installed trunk
via NPM, you will need to run it by using npm exec
. In the rest of the documentation, all commands will be shown as trunk <subcommand>
for brevity.
Other installs
Follow the wizard, you'll be prompted with the following options:
Sign up or log in
: Connect the CLI with your Trunk account to enable all of Trunk's feature.Trunk will automatically enable the most useful linters based on the files in your repo.
Trunk will manage your git hooks and enable some built-in hooks.
: This sets up Trunk to run automatically on commit and before you push, saving you time waiting for CI only to have it fail.Trunk will now run a local, one-time scan of your code and report any issues it finds
: This initial scan will give you a good overview of the problem areas in your code. Subsequent scans will only run on changed lines using hold-the-line.
Trunk is Git aware
Trunk speeds up your linting process by running on only the files that have changed in your branch compared to upstream. This means if you're using a base/trunk branch that's not master
or main
, you will need to specify it in your .trunk/trunk.yaml
The .trunk Directory
After initialization, a new folder .trunk
will be generated with the following content.
You will spend most of your time configuring Trunk Code Quality's linter definitions trunk.yaml
and individual linter configurations in configs
.
Recommended Linters
During initialization, Trunk Code Quality will recommend some linters based on files found in your project. Trunk Code Quality will recommend common linters for your language, but the full list of supported linters can be found here.
You can enable and disable individual linters by running:
You can also see all linters and whether they're enabled by running:
IDE Integration
Trunk Code Quality supports VSCode and Neovim through extensions. Using VSCode and Neovim will provide inline linter annotations as you code.
Move Existing Configs
If you have existing linter configs in your repo, you can move them into the .trunk/configs
folder. These config files will be symlinked in during any trunk check
run.
If you're using an IDE Extension like clangd
with an LSP that relies on those configs being in the root, you must create an additional symlink from the hidden config to the workspace root.
Next Steps
After initializing Trunk Code Quality, you can check for issues and configure Code Quality. The next steps in Setup & Installation will walk you through this process.
Last updated