Integrating Linters
Overview of defining linter integrations
Linter Integration
Trunk Check's linter integrations are fully configurable. This means that you can easily tune existing linters or leverage our caching and hold-the-line solution with your own custom linters.
Lint Config Definitions
Lint configuration is done in the lint
section of the trunk.yaml file. There are three parts:
Lint Config: defines overall linting.
Linter Definition: definition of a single linter
Linter Command Definition: definition of a command within the linter
The final config used at runtime is created by importing .yaml
files from the plugins repo for each linter, merging them into a tree structure, then overriding values from your repo's trunk.yaml
file to yield the final configuration.
Linter Definition
Every linter defined in lint.definitions
must specify at least a name, the types of files it will run on, at least one command, and success_codes
or error_codes
.
A complete linter definition defines the following:
Dependencies: Where to get the linter and its dependencies from? If the linter uses a runtime like Python or NodeJS, then Trunk also needs to know what versions it needs, and any support packages. See Dependencies for more.
Outputs: Trunk supports commands which produce output in one of several standard formats.
Custom Parsers: Linters can also use custom parsers if needed.
Execution Model
Running trunk check
tells trunk
to do the following:
compute the set of modified files (by comparing the current working tree and
upstream-ref
, usually yourmain
ormaster
branch)compute the set of lint actions to run based on the modified files
each enabled linter is invoked once per applicable modified file;
download and install any newly enabled linters/formatters
execute uncached lint actions
parse linter outputs into configurable output types
determine which lint issues are new, existing, or fixed
present the list of issues to the user
Reference
Full Tutorial on creating a linter form scratch in NodeJS
Last updated