Output
Output Sources
The output format that Trunk expects from a linter is determined by its output
type.
stdout
, stderr
or tmp_file
trunk
generally expects a linter to output its findings to stdout
, but does support other output mechanisms:
read_output_from
Description
stdout
Standard output.
stderr
Standard error.
tmp_file
If ${tmpfile}
was specified in command
, the path of the created ${tmpfile}
.
Output Types
Trunk supports several different generic output types. Most linters will use one of these output types, but if your linter doesn't conform well to any of these specifications, you can also write a custom parser. In general SARIF should be preferred over other formats because it is the most flexible and battle tested.
Trunk currently supports the following linter output types.
Linter Type
Autofix support
Description
If your linter produces a different output type, you can also write a parser to transform the linter's output into something Trunk can understand.
SARIF
output: sarif
linters produce diagnostics in the Static Analysis Results Interchange Format:
LSP JSON
output: lsp_json
linters output issues as Language Server Protocol JSON.
Pass/Fail Linters
output: pass_fail
linters find either:
no issues in a file, indicated by exiting with
exit_code=0
, ora single file-level issue in a file, whose message is the linter's
stdout
, indicated by exiting withexit_code=1
.
Note: Exiting with
exit_code=1
but writing nothing tostdout
is considered to be a linter tool failure.Note:
pass_fail
linters are required to havesuccess_codes: [0, 1]
Regex
output: regex
linters produce output that can be parsed with custom regular expressions and named capture groups. The regular expression is specified in the parse_regex
field.
regex
supports capturing strings from a linter output for the following named capture groups:
path
: file path (required)line
: line numbercol
: column numberseverity
: one ofnote
,notice
,allow
,deny
,disabled
,error
,info
,warning
code
: linter diagnostic codemessage
: description
For example, the output
can be parsed with the regular expression
and would result in a trunk
diagnostic that looks like this:
In the event that multiple capture groups of the same name are specified, the nonempty capture will be preferred. If there are multiple non-empty captures, a linter error will be thrown. Adjust your regular expression accordingly to match the specifics of your output.
Note: For additional information on building custom regular expressions, see re2. More complicated regex may require additional escape characters in yaml configuration.
Arcanist
You can also output JSON using the Arcanist format.
Formatters
output: rewrite
linters write the formatted version of a file to stdout
; this becomes an autofix which trunk
can prompt you to apply (which is what trunk check
does by default) or automatically apply for you (if you trunk check --fix
or trunk fmt
).
For example, if you wanted a linter to normalize your line endings, you could do this:
Setting formatter: true
will cause trunk fmt
to run this linter.
Last updated