-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvalidate-markdown-lint.js
More file actions
75 lines (65 loc) · 1.7 KB
/
Copy pathvalidate-markdown-lint.js
File metadata and controls
75 lines (65 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env node
/**
* Lint changed Markdown files, excluding known exceptions
* Replaces multiline shell logic with Node.js
*/
import { execFileSync } from "child_process";
const eventName = process.env.GITHUB_EVENT_NAME;
const baseSha = process.env.BASE_SHA;
const headSha = process.env.HEAD_SHA;
// Skip for non-push/pull_request events
if (eventName !== "pull_request" && eventName !== "push") {
console.log(`Skipping markdown lint for event ${eventName}`);
process.exit(0);
}
// Get changed markdown files
let files = [];
try {
const output = execFileSync("git", [
"diff",
"--name-only",
baseSha,
headSha,
"--",
"*.md",
"*.mdx",
]);
files = output
.toString()
.split("\n")
.filter((f) => f.trim());
} catch (error) {
console.error("Failed to get changed files:", error.message);
process.exit(1);
}
// Exclude known exceptions
const excludePatterns = [
/^AWESOME_GITHUB_MAPPING_STRATEGY\.md$/,
/^docs\/MIGRATION\.md$/,
/^\.github\/reports\//,
/^projects\/active\//,
/\/plugin-provided\//,
/\/platform-managed\//,
/\/directory-installed\//,
/\/tests\/markdown-issues\.md$/,
/\/agentskills-main\//,
];
const filteredFiles = files.filter((file) => {
return !excludePatterns.some((pattern) => pattern.test(file));
});
if (filteredFiles.length === 0) {
console.log(
"No Markdown files to lint (all changed files are in ignore list).",
);
process.exit(0);
}
console.log(`Linting ${filteredFiles.length} changed markdown file(s)...`);
// Run markdownlint-cli2
try {
execFileSync("npx", ["markdownlint-cli2", ...filteredFiles], {
stdio: "inherit",
});
} catch (error) {
console.error("Markdown linting failed");
process.exit(1);
}