@@ -56,7 +56,7 @@ Templates can also access the following functions:
5656| ` blue ` | ` string ` | Returns the given ` string ` with an ANSI-formatted blue foreground color. |
5757| ` yellow ` | ` string ` | Returns the given ` string ` with an ANSI-formatted yellow foreground color. |
5858| ` underline ` | ` string ` | Returns the given ` string ` with an ANSI-formatted underline. |
59- | ` newTable ` | ` bool ` | Creates a new [ ` tablewriter ` ] [ 2 ] struct. ` newTable ` accepts one boolean value representing [ ` SetAutoWrapText ` ] [ 2 ] . |
59+ | ` newTable ` | ` bool ` | Creates a new [ ` tablewriter ` ] [ 2 ] struct. ` newTable ` accepts one boolean value representing [ ` SetAutoWrapText ` ] [ 3 ] . |
6060| ` addRow ` | ` []string ` | Appends the given row to a table. |
6161| ` renderTable ` | ` Table ` | Prints the table-formatted output to ` stdout ` . |
6262| ` jsonEscape ` | ` string ` | Ensure the given ` STRING ` is valid JSON. |
@@ -65,6 +65,8 @@ See the [Sprig Function Documentation][4] for the full list.
6565
6666## Examples
6767
68+ ### Customizing the default output
69+
6870The following example re-implements Vale's default output style using a
6971template.
7072
@@ -111,7 +113,50 @@ template.
111113{{- $e}} {{" errors" | red}}, {{$w}} {{" warnings" | yellow}} and {{$s}} {{" suggestions" | blue}} in {{$f}} {{$f | int | plural " file" " files" }}.
112114```
113115
116+ ### Creating a RDJSONL template
117+
118+ The following example converts Vale's output to [ RDJSONL] [ 5 ] ,
119+ which you can then pass to [ Reviewdog] [ 6 ] to display on pull request.
120+ This can be useful when the [ Vale action] [ 7 ] is not suitable for your workflow.
121+
122+ ``` go
123+ {{- /* Range over the linted files */ -}}
124+
125+ {{- range .Files }}
126+
127+ {{- $path := .Path -}}
128+
129+ {{- /* Range over the file's alerts */ -}}
130+
131+ {{- range .Alerts -}}
132+
133+ {{- $error := " " -}}
134+ {{- if eq .Severity " error" -}}
135+ {{- $error = " ERROR" -}}
136+ {{- else if eq .Severity " warning" -}}
137+ {{- $error = " WARNING" -}}
138+ {{- else -}}
139+ {{- $error = " INFO" -}}
140+ {{- end}}
141+
142+ {{- /* Variables setup */ -}}
143+
144+ {{- $line := printf " %d " .Line -}}
145+ {{- $col := printf " %d " (index .Span 0 ) -}}
146+ {{- $check := printf " %s " .Check -}}
147+ {{- $message := printf " %s " .Message -}}
148+
149+ {{- /* Output */ -}}
150+
151+ {" message" : " [{{ $check }}] {{ $message | jsonEscape }}" , " location" : {" path" : " {{ $path }}" , " range" : {" start" : {" line" : {{ $line }}, " column" : {{ $col }}}}}, " severity" : " {{ $error }}" }
152+ {{end -}}
153+ {{end -}}
154+ ```
155+
114156[ 1 ] : https://golang.org/pkg/text/template/
115157[ 2 ] : https://github.com/olekukonko/tablewriter#ascii-table-writer
116158[ 3 ] : https://godoc.org/github.com/olekukonko/tablewriter#Table.SetAutoWrapText
117159[ 4 ] : http://masterminds.github.io/sprig/
160+ [ 5 ] : https://github.com/reviewdog/reviewdog?tab=readme-ov-file#reviewdog-diagnostic-format-rdformat
161+ [ 6 ] : https://github.com/reviewdog/reviewdog
162+ [ 7 ] : https://github.com/errata-ai/vale-action
0 commit comments