Skip to content

Commit 0447ab2

Browse files
committed
Enhance changenote validation to support nested bullet lists
1 parent 50ec5a5 commit 0447ab2

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

‎scripts/changetool/cli/validate.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ await describe("isValidChangenoteContent", async () => {
7474
"+ Fixed a bug\n+ Added feature",
7575
"- Fixed a bug\n* Added feature",
7676
"- Fixed a bug\n+ Added feature",
77+
"- Fixed a bug\n * Added feature\n + Updated docs",
7778
"\n\n\n* Fixed a bug",
7879
"\n\n\n+ Fixed a bug",
7980
"---\n* Fixed a bug\n* Added feature",

‎scripts/changetool/cli/validate.ts‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as fs from "node:fs";
22
import * as path from "node:path";
33

44
import { matter } from "lite-matter";
5+
import type { List, ListItem } from "mdast";
56
import { fromMarkdown } from "mdast-util-from-markdown";
67

78
// Regex for filename: YYYY-MM-DD-id.md
@@ -30,19 +31,28 @@ export const VALID_CHANGE_NOTE_CATEGORIES = {
3031
*/
3132
export function isValidChangenoteContent(content: string): boolean {
3233
const ast = fromMarkdown(content);
34+
const lines = content.split("\n");
3335

34-
if (
35-
ast.children.length !== 1 ||
36-
ast.children[0].type !== "list" ||
37-
ast.children[0].ordered === true
38-
) {
39-
return false;
36+
function listHasHyphenBullets(node: List | ListItem): boolean {
37+
if (node.type === "list") {
38+
return node.children.every(listHasHyphenBullets);
39+
}
40+
41+
const line = lines[node.position!.start.line - 1].trim();
42+
return (
43+
line.startsWith("-") &&
44+
node.children.every(
45+
(child) => child.type !== "list" || listHasHyphenBullets(child),
46+
)
47+
);
4048
}
4149

42-
const lines = content.split("\n");
43-
return ast.children[0].children.every((listItem) => {
44-
return lines[listItem.position!.start.line - 1].startsWith("-");
45-
});
50+
return (
51+
ast.children.length === 1 &&
52+
ast.children[0].type === "list" &&
53+
ast.children[0].ordered === false &&
54+
listHasHyphenBullets(ast.children[0])
55+
);
4656
}
4757

4858
/**

0 commit comments

Comments
 (0)