Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make LintedTotal available in custom template #270

Merged

Conversation

ashmckenzie
Copy link
Contributor

馃憢 Hi 馃檪 This PR makes the linted file count available when using custom templates.

Using the custom template:

{{- /* Modify Vale's output https://docs.errata.ai/vale/cli#--output */ -}}

{{- /* Keep track of our various counts */ -}}

{{- $e := 0 -}}
{{- $w := 0 -}}
{{- $s := 0 -}}
{{- $f := 0 -}}

{{- /* Range over the linted files */ -}}

{{- range .Files}}

{{- $f = add1 $f -}}
{{- $path := .Path | underline -}}

{{- /* Range over the file's alerts */ -}}

{{- range .Alerts -}}

{{- $error := "" -}}
{{- if eq .Severity "error" -}}
    {{- $error = .Severity | red -}}
    {{- $e = add1 $e  -}}
{{- else if eq .Severity "warning" -}}
    {{- $error = .Severity | yellow -}}
    {{- $w = add1 $w -}}
{{- else -}}
    {{- $error = .Severity | blue -}}
    {{- $s = add1 $s -}}
{{- end}}

{{- /* Variables setup */ -}}

{{- $path = $path -}}
{{- $loc := printf "Line %d, position %d" .Line (index .Span 0) -}}
{{- $check := printf "%s" .Check -}}
{{- $message := printf "%s" .Message -}}
{{- $link := printf "%s" .Link -}}

{{- /* Output */ -}}

{{ $path }}:
 {{ $loc }} (rule {{ $check }})
 {{ $error }}: {{ $message }}
 More information: {{ $link }}

{{end -}}
{{end -}}

{{- $e}} {{"errors" | red}}, {{$w}} {{"warnings" | yellow}} and {{$s}} {{"suggestions" | blue}} in {{$f}} of {{.LintedTotal}} {{.LintedTotal | plural "file" "files"}}.

And running, produces:

$ vale --config .vale.ini --minAlertLevel error --output .vale/vale.tmpl **/*.md
--snip--
3 errors, 0 warnings and 0 suggestions in 2 of 18 files.

@Ravlen
Copy link

Ravlen commented Nov 16, 2020

@ashmckenzie Hey, I didn't realize you were taking a look! Let me mark this as related to #269 馃槈

Closes #269

@jdkato jdkato merged commit e2f4984 into errata-ai:v2 Nov 16, 2020
@ashmckenzie ashmckenzie deleted the ashmckenzie/include-lined-total-count branch November 16, 2020 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants