Command Line

The following commands are available when using trunk from the command line

$ trunk check       # runs the universal linter on all applicable files
$ trunk fmt         # runs all the enabled formatters and auto-applies changes

You can always find this list using trunk check --help.

check

trunk check runs linters & formatters on your changed files, prompting you to apply fixes. Without additional args, trunk check will run all applicable linters on all files changed in the current branch.

fmt

Run all applicable formatters as configured in trunk.yaml. trunk fmt is short-hand for running
trunk check with a --fix --filter set to all formatters enabled in your repository.

options
--allRun on all the files in the repository. Useful if trying to assess a new linter in the system, or to find and fix pre-existing issues
--fixAuto-apply all suggested fixes
--no-fixSurface, but do not prompt for autofixes
--filterList of comma-separated linters to run. Specify --filter=-linter to disable a linter.
--sample=NRun check on a sampling of all files in the repo
--ciRun in Continuous Integration mode
--no-progressDo not show progress while running
--ci-progressOnly show progress every 30s while running (useful for CI jobs). Implied by --ci.
--outputOutput results in specified format: text (default) or json
--output-file=FILEWrite json results to specified file
--show-fixedInclude fixed issues in the output
--helpOutput help information

Recipes

CheckCommand
all filestrunk check --all --no-fix
a specific filetrunk check some/file.py
all applicable files with flake8trunk check --all --no-fix --filter=flake8
the behavior of all linterstrunk check --sample 5
the behavior of a specific lintertrunk check --sample 5 --filter=flake8
the formatting of the whole repotrunk fmt --all
the formatting of a specific filetrunk fmt some/file.py
the formatting of all python code with blacktrunk fmt --all --filter=black

Options

--filter

--filter argument allows you to restrict trunk check to a subset of the linters enabled in your repository.

For example, to run eslint and isort on the entire repo:

trunk check --all --filter=eslint,isort

Alternatively, to run every linter except clang-tidy and shellcheck:

trunk check --all --filter=-clang-tidy,-shellcheck

--sample

--sample=N will attempt to run every enabled linter against the requested number of files. The goal of the sample flag is to test the setup of the linters in your repository as well as any specific configuration they might honor.

The sample command will attempt to run each linter N times, but may run fewer if not enough applicable files exist in your set of files to lint. --sample=N can be combined with any other set of options for trunk check.

For example, to run prettier against 10 different prettier supported files:

trunk check --sample=10 --filter=prettier

Alternatively to run every linter at most 5 times against each enabled linter:

trunk check --sample=5

Discover new tools and available upgrades

trunk upgrade check will upgrade all the enabled linters in your repository to the latest versions of those tools. We highly recommend running on the latest released versions of tools as updates will frequently include important security fixes and additional valuable checks.

Upgrade will also recommend new tools that have become applicable since the last time your repository was scanned. This can be a result of using new technologies in your repository or trunk itself shipping with new applicable tools. If you don't like a particular recommendation you can run trunk check disable {tool-name} to teach trunk not to recommend it.

Options
--dry-runReport on all upgradable tools.
--helpOutput help information

Pinned System Versions

When you enable a packaged or downloaded linter in your trunk.yaml and don't specify a version, trunk will attempt to use the version of that tool installed on your system. Trunk will not automatically suggest upgrades for this tool. If you wish to upgrade to the latest version, you will first have to specify a base version in your trunk.yaml.

Advanced Features

Options & FlagsExplanation
--rootExplicitly set the root of the repository to run against
--upstreamSpecify the upstream branch used to calculate new vs existing issued.
--triggerSupports running trunk check from inside a git hook. Options are manual (default), git-push, git-commit. Controls whether the check returns early and it's interactivity.