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:

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:

  • Enabling: When to auto-enable the linter. Should the linter be enabled when certain config files are available? See Enabling for more.

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

  • Files: When to use the linter. This includes which filetypes the linter uses, which files could potentially affect caching, and if the linter is idempotent. See Files for more.

  • Commands: Once the final set of files are computed Trunk will invoke one of the linter's commands. A command defines the input targets, input sources, and the actual binary that is run for the command, and the exit codes to indicate success. See Commands 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 your main or master branch)

  • compute the set of lint actions to run based on the modified files

  • 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

Last updated