Linters
Overview of Trunk Check's supported linters and configuration
Trunk Check supports over 100 different linters and formatters out of the box. The configurations for trunk check
and trunk fmt
are governed by the lint
section of the trunk.yaml
file stored in the .trunk
directory of your git repo. Here's an example of what a fully-featured lint
section looks like:
Test your config changes
Normally when you run trunk check
or trunk fmt
it runs only on files you've changed. We've made it easy to test how a linter will behave in your repo. As you're tuning your linter configuration simply run check with the --sample
flag. When sampling, Trunk will find applicable files for the linters you've enabled and show you how the linter will behave against a sampling of inputs.
Sample | Command |
---|---|
all linters on 5 files |
|
a specific linter with 7 files |
|
all linters on a specific file |
|
In sampling mode, Trunk may run multiple linters on a single file, and may not run each linter on the full number of requested samples (if not enough applicable files can be found).
Tuning your linters
Most linters offer some form of configuration. Trunk uses the native configuration setup of all the tools it runs. No need to learn a new config language or hunt for specific ways to tune a linter inside trunk. Whether it's clang-tidy
, eslint
, or any other linter, all the documentation you'll find online about it is still applicable. We're proud to stand on the shoulders of giants and believe that the open source communities building these tools know best how they should work. Our goal is simply to make it as easy as possible for you to adopt these tools.
To configure what a linter does, you will continue to use the linter's own config files. Check out our configs repository for always-up-to-date linter configs and some tips on how to structure your linters and repo. Check out our docs on linter-specific tips. To configure how Trunk runs a linter, read on.
Moving linter configs
If you'd like, Trunk also supports migrating any linter configurations from the root of your repository into a .trunk/configs
folder. These config files will be symlinked in during any trunk check
run. Note that if you're using an IDE Extension like clangd with an LSP that relies on those configs being in the root, you will need to create an additional symlink from the hidden config to the workspace root.
If you find that you want to tweak how Trunk runs a given linter, you may want to consult the documentation on overriding defaults and the various linter settings; for example, hold-the-line is enabled by default for most linters, but can be disabled like so:
Disabling hold-the-line for a linter will require that all issues found by said linter be fixed before changes to that file can be landed.
Disabling the upstream for a linter will elide the execution of the linter on the upstream.
Enable Linters
Trunk only runs linters listed in the enabled
section; linters which are defined in lint.definitions
but are not listed in enabled
are not run.
When enabling a linter, you must specify a version for the linter:
Custom linters are slightly different; see those docs to learn more.
You can also ask Trunk to detect new linters and upgrade existing linters to their latest respective versions by running trunk upgrade check
.
Disable Linters
Trunk will continuously monitor your repository and make recommendations of additional new tools to run on your codebase. You can tell trunk not to recommend a specific linter by adding it to the disabled list.
Installing additional packages
We support installing additional packages along with your linter. For example, Pylint supports adding plugins which are installable as pip packages. For example, if you want to run the plugin pylint-django
as part of your setup, you need to tell Trunk to install the package:
Runtime versioning
By default Trunk will install hermetic versions of runtimes required by the linters you have chosen. If you need to peg to a specific runtime version or you want to use the version installed on your system, consult the runtimes documentation.
Ignoring Issues and Files
By default Check will ignore issues in files which are listed in the .gitignore
file.
If you want to ignore groups of files, such as generated code, you can do that with the lint.ignore
section of your .trunk/trunk.yaml
file. ex:
You can also ignore particular issues within a file using special comments like this:
This tells Trunk that the clang-tidy
linter found a modernize-use-nullptr
issue on the highlighted line and that Trunk should suppress this linter issue.
For full details please see the Ignoring Issues and Files page.
Blocking Thresholds
All issue severities are considered blocking by default. In cases where you might want to slowly try out a new linter, we provide a mechanism to set specific thresholds for each linter.
Every entry in threshold
defines a set of linters and the severity threshold that is considered blocking. In this example, we're saying that only high
lint issues should be considered blocking for clang-tidy
.
Key | Value |
---|---|
linters | List of linters (e.g. |
level | Threshold at which issues are considered blocking. One of : |
Trigger rules
Some linters do not operate on individual files. Instead you must lint your entire repo at once. The way this is handled in trunk is to set up a trigger rule. Most linters will not require the use of a trigger rule.
Trigger rules work on 3 principles:
Input(s) that trigger the linters. These can be files, directories, or extended globs.
Linter(s) to run when a triggered file is modified.
Targets(s) to pass to the linters (can be files or directories).
An example for ansible-lint:
Triggered linters will also be run when executing trunk check with --all
so long as a file exists that matches one of the listed paths.
You may use .
as a target to run on the entire repo instead of an isolated directory.
File Size
By default, Trunk only lints files up to 4 MiB in size. To override this globally, specify a default_max_file_size
in lint
:
To override this for a specific linter, specify a max_file_size
in its definition:
Timeout
Each linter has a default timeout of 10 minutes. If its execution takes longer than this amount of time, Trunk Check will terminate the process and return an error to the user.
To override the timeout for a specific linter, specify a run_timeout
in its definition:
The run_timeout
value can be specified in seconds (s
), minutes (m
), or hours (h
).
Last updated