From 73408c933e56671422fcf362759ff8993dda912d Mon Sep 17 00:00:00 2001 From: Patrice Chalin Date: Thu, 27 Jul 2023 09:21:07 -0400 Subject: [PATCH] [editorial][CI] Ensure markdownlint has proper exit status (#210) Co-authored-by: Josh Suereth --- gulpfile.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index a42fd496e5..b01927ecc0 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -4,8 +4,8 @@ const markdownlint = require("markdownlint"); const yaml = require("js-yaml"); const fs = require("fs"); -let fileCount = 0, - issueCount = 0; +let numFilesProcessed = 0, + numFilesWithIssues = 0; function markdownLintFile(file, encoding, callback) { const config = yaml.load(fs.readFileSync("./.markdownlint.yaml", "utf8")); @@ -33,9 +33,11 @@ function markdownLintFile(file, encoding, callback) { .join("\n"); if (resultString) { console.log(resultString); - issueCount++; + numFilesWithIssues++; + // Don't report an error yet so that other files can be checked: + // callback(new Error('...')); } - fileCount++; + numFilesProcessed++; callback(null, file); }); } @@ -47,11 +49,13 @@ function lintMarkdown() { .src(markdownFiles) .pipe(through2.obj(markdownLintFile)) .on("end", () => { - console.log( - `Processed ${fileCount} file${ - fileCount == 1 ? "" : "s" - }, ${issueCount} had issues.`, - ); + const fileOrFiles = "file" + (numFilesProcessed == 1 ? "" : "s"); + const msg = `Processed ${numFilesProcessed} ${fileOrFiles}, ${numFilesWithIssues} had issues.`; + if (numFilesWithIssues > 0) { + throw new Error(msg); + } else { + console.log(msg); + } }); }