Commit b30b6f5e authored by Evan Read's avatar Evan Read

Merge branch 'docs-update-vale-add-template' into 'master'

Update vale and start using output template

See merge request gitlab-org/gitlab!47487
parents aa9dbddc ff3777c4
......@@ -42,7 +42,7 @@ docs-lint markdown:
extends:
- .default-retry
- .docs:rules:docs-lint
image: "registry.gitlab.com/gitlab-org/gitlab-docs/lint:ruby-2.7.2-alpine-3.12-vale-2.4.3-markdownlint-0.24.0"
image: "registry.gitlab.com/gitlab-org/gitlab-docs/lint-markdown:alpine-3.12-vale-2.6.1-markdownlint-0.24.0"
stage: test
needs: []
script:
......
{{- /* 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}} found in {{$f}} {{$f | int | plural "file" "files"}}.
This diff is collapsed.
......@@ -75,14 +75,13 @@ fi
function run_locally_or_in_docker() {
local cmd=$1
local args=$2
local pipe_cmd=$3
if hash ${cmd} 2>/dev/null
then
$cmd $args | $pipe_cmd
$cmd $args
elif hash docker 2>/dev/null
then
docker run -t -v ${PWD}:/gitlab -w /gitlab --rm registry.gitlab.com/gitlab-org/gitlab-docs/lint:latest ${cmd} ${args} | $pipe_cmd
docker run -t -v ${PWD}:/gitlab -w /gitlab --rm registry.gitlab.com/gitlab-org/gitlab-docs/lint:latest ${cmd} ${args}
else
echo
echo " ✖ ERROR: '${cmd}' not found. Install '${cmd}' or Docker to proceed." >&2
......@@ -109,7 +108,7 @@ else
fi
echo '=> Linting prose...'
run_locally_or_in_docker 'vale' "--minAlertLevel error --output=JSON ${MD_DOC_PATH}" "ruby scripts/vale.rb"
run_locally_or_in_docker 'vale' "--minAlertLevel error --output=doc/.vale/vale.tmpl ${MD_DOC_PATH}"
if [ $ERRORCODE -ne 0 ]
then
......
#!/usr/bin/env ruby
#
# Get the JSON output from Vale and format it in a nicer way
# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/46725
#
# Usage:
# vale --output=JSON filename.md | ruby vale.rb
#
require 'json'
input = ARGF.read
data = JSON.parse(input)
data.each_pair do |source, alerts|
alerts.each do |alert|
puts "#{source}:"
puts " Line #{alert['Line']}, position #{alert['Span'][0]} (rule #{alert['Check']})"
puts " #{alert['Severity']}: #{alert['Message']}"
puts " More information: #{alert['Link']}"
puts
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment