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 never auto-apply a suggested fix
--filterList of comma-separated linters to run. Specify --filter=-linter to disable a linter.
--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
--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

--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

Run each linter on a sample of 5 files

trunk check --all --sample=5

This may run multiple linters on a single file, and may not run each linter on the full number of files (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.

Discover new tools and available upgrades

trunk upgrade --filter=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

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.

Did this page help you?