For the complete documentation index, see llms.txt. This page is also available as Markdown.

Templates

Learn about Vale's output templates.

By default, Vale includes support for three output styles: line, JSON, and CLI (the default). You can specify which style to use via the --output flag:

$ vale --output=line README.md

In addition to the three provided output styles, Vale also supports custom output styles powered by Go’s text/template package.

To use a custom format, pass the path to a template file through the --output option:

$ vale --output='template.tmpl' somefile.md

Where template.tmpl is a file that contains a valid Go template stored in the <StylesPath>/config/templates directory.

Templating

Templates have access to the following data structures:

type ProcessedFile struct {
    Alerts []core.Alert
    Path   string
}

type Data struct {
    Files       []ProcessedFile
    LintedTotal int
}

Where core.Alert has the same information as Vale’s --output=JSON object.

Templates can also access the following functions:

Name
Argument(s)
Description

red

string

Returns the given string with an ANSI-formatted red foreground color.

blue

string

Returns the given string with an ANSI-formatted blue foreground color.

yellow

string

Returns the given string with an ANSI-formatted yellow foreground color.

underline

string

Returns the given string with an ANSI-formatted underline.

newTable

bool

Creates a new tablewriter struct. newTable accepts one boolean value representing SetAutoWrapText.

addRow

[]string

Appends the given row to a table.

renderTable

Table

Prints the table-formatted output to stdout.

jsonEscape

string

Ensure the given STRING is valid JSON.

See the Sprig Function Documentation for the full list.

Examples

Customizing the default output

The following example re-implements Vale’s default output style using a template.

Creating a RDJSONL template

The following example converts Vale’s output to RDJSONL, which you can then pass to Reviewdog to display on pull request. This can be useful when the Vale action is not suitable for your workflow.

Two things are worth knowing when adapting this. Reviewdog reads a range, so giving it the end of the span -- Span is inclusive, and Reviewdog's end is not -- is what underlines the match rather than pointing at its first character. And Reviewdog counts columns in UTF-8 bytes where Vale counts characters, so the two agree only until a line picks up its first multi-byte character; converting between them needs the source line, which a template can't read.

Creating a SARIF template

The following example converts Vale's output to SARIF, the format that GitHub code scanning, GitLab, and Azure DevOps read. Unlike a pull request comment, an alert reported this way persists: it has a history, and someone can dismiss it with a reason.

In a GitHub workflow, hand the file to upload-sarif:

Two details make the conversion straightforward. SARIF measures columns in characters, as Vale's Span does, so the positions carry over unchanged. And SARIF asks for each rule to be described once, which dict and set collect in a pass over the alerts before any output.

Last updated