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
:
Fixing issues in pull requests
To confirm that you've fixed issues identified by Trunk Code Quality before pushing your pull request, just run trunk check
.
If Trunk continues to identify new Code Quality issues on your PR, first try merging the latest changes from your base branch. When Trunk runs on a PR, it runs on a commit that merges your PR into its base branch, just like GitHub workflows.
If this continues to fail, then run git checkout refs/pull/<PR number>/merge && trunk check
. This is a reference to the merge commit GitHub creates.
Skipping Trunk Code Quality on PRs
You can include /trunk skip-check
in the body of a PR description (i.e. the first comment on a given PR) to mark Trunk Code Quality as "skipped". Trunk Code Quality will still run on your PR and report issues, but this will allow the PR to pass a GitHub-required status check on Trunk Check
.
This can be helpful if Code Quality is flagging known issues in a given PR that you don't want to ignore, which can come in handy if you're doing a large refactor.
Last updated