Initialize Trunk
Last updated
Last updated
Before you can start using Trunk Code Quality, you need to install and initialize Trunk in your repo. This page covers the initialization process.
The Trunk CLI can be installed in many different ways depending on your use case.
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:
You can install the 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.
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.
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.
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 features.
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.
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
.
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:
Trunk Code Quality supports VSCode and Neovim through extensions. Using VSCode and Neovim will provide inline linter annotations as you code.
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.
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.