Prevent New Issues
Trunk operates in hold-the-line mode by default. This Trunk will run linters only on the files that have changed according to Git, by comparing it to the appropriate upstream branch.
If you're not using main
or master
as the base branch, make sure it's specified in .trunk/trunk.yaml
.
Prevent Issues On Commits
Code Quality can automatically run formatters on each commit to prevent new formatting from appearing in your commit history. Code Quality uses a Git hook to automate this process. Formatting changes will automatically be applied to what you commit.
This enables a Git hook managed by Trunk which is defined in the trunk.yaml
config file. When other developers pull the updated trunk.yaml
file, they will automatically have this Git hook enabled to run trunk fmt
on each commit.
Prevent Issues Before Push
Code Quality can automatically run linters and formatters on each commit to prevent new formatting from appearing in your commit history. Code Quality uses a Git hook to automate this process. This will flag lint issues so they never make it into your PRs.
This enables a Git hook managed by Trunk which is defined in the trunk.yaml
config file. When other developers pull the updated trunk.yaml
file, they will automatically have this Git hook enabled to run trunk check
before each push.
Prevent Issues on PRs
Trunk Code Quality can work in CI to check for problems when a new pull request is opened.
GitHub Actions Workflows
If you're already running linters on your PRs, you can replace your lint step with the Trunk Code Quality action step. For example:
This step will automatically run Trunk Code Quality to reveal problems found when comparing the branch to main
.
When post-annotations
is set to true
Code Quality will also annotate the PR with comments for where lint issues are found.
Manual Configuration and Non-GitHub CI
If you want to run the trunk check
command directly in your workflow, or you're not using GitHub, you can run the following command:
If you setup Trunk with npm
and added trunk commands to your package.json
like mentioned in Initialize Trunk, you can run the following command:
If you committed Trunk Launcher into your project, you can run:
Here's an example GitHub Action Workflow and pnpm
:
Last updated