Skip to content

Commit 73408c9

Browse files
chalinjsuereth
andauthored
[editorial][CI] Ensure markdownlint has proper exit status (open-telemetry#210)
Co-authored-by: Josh Suereth <joshuasuereth@google.com>
1 parent a5509c6 commit 73408c9

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

gulpfile.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const markdownlint = require("markdownlint");
44
const yaml = require("js-yaml");
55
const fs = require("fs");
66

7-
let fileCount = 0,
8-
issueCount = 0;
7+
let numFilesProcessed = 0,
8+
numFilesWithIssues = 0;
99

1010
function markdownLintFile(file, encoding, callback) {
1111
const config = yaml.load(fs.readFileSync("./.markdownlint.yaml", "utf8"));
@@ -33,9 +33,11 @@ function markdownLintFile(file, encoding, callback) {
3333
.join("\n");
3434
if (resultString) {
3535
console.log(resultString);
36-
issueCount++;
36+
numFilesWithIssues++;
37+
// Don't report an error yet so that other files can be checked:
38+
// callback(new Error('...'));
3739
}
38-
fileCount++;
40+
numFilesProcessed++;
3941
callback(null, file);
4042
});
4143
}
@@ -47,11 +49,13 @@ function lintMarkdown() {
4749
.src(markdownFiles)
4850
.pipe(through2.obj(markdownLintFile))
4951
.on("end", () => {
50-
console.log(
51-
`Processed ${fileCount} file${
52-
fileCount == 1 ? "" : "s"
53-
}, ${issueCount} had issues.`,
54-
);
52+
const fileOrFiles = "file" + (numFilesProcessed == 1 ? "" : "s");
53+
const msg = `Processed ${numFilesProcessed} ${fileOrFiles}, ${numFilesWithIssues} had issues.`;
54+
if (numFilesWithIssues > 0) {
55+
throw new Error(msg);
56+
} else {
57+
console.log(msg);
58+
}
5559
});
5660
}
5761

0 commit comments

Comments
 (0)