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/templatearrow-up-right 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.

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 tablewriterarrow-up-right struct. newTable accepts one boolean value representing SetAutoWrapTextarrow-up-right.

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 Documentationarrow-up-right for the full list.

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

The following example converts Vale’s output to RDJSONLarrow-up-right, which you can then pass to Reviewdogarrow-up-right to display on pull request. This can be useful when the Vale actionarrow-up-right is not suitable for your workflow.

Filters Views