From 750ee5f1684a9100e6eb7ce31f0cad88d65d2dbc Mon Sep 17 00:00:00 2001
From: Marcel Amirault <mamirault@gitlab.com>
Date: Tue, 2 Jul 2024 08:12:36 +0000
Subject: [PATCH] Output count of linted docs in vale

---
 doc/.vale/vale.tmpl | 5 +----
 scripts/lint-doc.sh | 6 +++++-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/doc/.vale/vale.tmpl b/doc/.vale/vale.tmpl
index 8a6c6e5157dc4..3fe958023b9f2 100644
--- a/doc/.vale/vale.tmpl
+++ b/doc/.vale/vale.tmpl
@@ -5,13 +5,10 @@
 {{- $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 */ -}}
@@ -48,4 +45,4 @@
 {{end -}}
 {{end -}}
 
-{{- $e}} {{"errors" | red}}, {{$w}} {{"warnings" | yellow}}, and {{$s}} {{"suggestions" | blue}} found.
+{{- $e}} {{"errors" | red}}, {{$w}} {{"warnings" | yellow}}, and {{$s}} {{"suggestions" | blue}} found in {{.LintedTotal}} {{.LintedTotal | int | plural "file" "files"}}.
diff --git a/scripts/lint-doc.sh b/scripts/lint-doc.sh
index d479d76e01fa9..e69f96fbd2df0 100755
--- a/scripts/lint-doc.sh
+++ b/scripts/lint-doc.sh
@@ -150,6 +150,7 @@ fi
 if [ -n "$1" ]
 then
   MD_DOC_PATH="$@"
+  MD_DOC_PATH_VALE="$@"
   # shellcheck disable=2059
   printf "${COLOR_GREEN}INFO: List of files specified on command line. Running Markdownlint and Vale for only those files...${COLOR_RESET}\n"
 elif [ -n "${CI_MERGE_REQUEST_IID}" ]
@@ -164,10 +165,12 @@ then
   if grep -E "\.vale|\.markdownlint|lint-doc\.sh|docs\.gitlab-ci\.yml" < $DOC_CHANGES_FILE
   then
     MD_DOC_PATH=${MD_DOC_PATH:-'doc/{*,**/*}.md'}
+    MD_DOC_PATH_VALE=${MD_DOC_PATH_VALE:-'doc/'}
     # shellcheck disable=2059
     printf "${COLOR_GREEN}INFO: Vale, Markdownlint, lint-doc.sh, or pipeline configuration changed. Testing all files.${COLOR_RESET}\n"
   else
     MD_DOC_PATH=$(cat $DOC_CHANGES_FILE)
+    MD_DOC_PATH_VALE=$(cat $DOC_CHANGES_FILE)
     if [ -n "${MD_DOC_PATH}" ]
     then
       # shellcheck disable=2059
@@ -177,6 +180,7 @@ then
   rm $DOC_CHANGES_FILE
 else
   MD_DOC_PATH=${MD_DOC_PATH:-'doc/{*,**/*}.md'}
+  MD_DOC_PATH_VALE=${MD_DOC_PATH_VALE:-'doc/'}
   # shellcheck disable=2059
   printf "${COLOR_GREEN}INFO: No merge request pipeline detected. Running Markdownlint and Vale on all files...${COLOR_RESET}\n"
 fi
@@ -235,7 +239,7 @@ fi
 
 # shellcheck disable=2059
 printf "${COLOR_GREEN}INFO: Looking for Vale to lint prose, either installed locally or available in documentation linting image...${COLOR_RESET}\n"
-run_locally_or_in_container 'vale' "--minAlertLevel error --output=doc/.vale/vale.tmpl" "${MD_DOC_PATH}"
+run_locally_or_in_container 'vale' "--minAlertLevel error --output=doc/.vale/vale.tmpl" "${MD_DOC_PATH_VALE}"
 
 if [ "$ERRORCODE" -ne 0 ]
 then
-- 
GitLab