Enhance changenote validation to support nested bullet lists

This commit is contained in:
Mario Campos
2026-08-26 23:06:47 -05:00
parent 50ec5a5c18
commit 0447ab23b5
2 changed files with 21 additions and 10 deletions

View File

@@ -74,6 +74,7 @@ await describe("isValidChangenoteContent", async () => {
"+ Fixed a bug\n+ Added feature",
"- Fixed a bug\n* Added feature",
"- Fixed a bug\n+ Added feature",
"- Fixed a bug\n * Added feature\n + Updated docs",
"\n\n\n* Fixed a bug",
"\n\n\n+ Fixed a bug",
"---\n* Fixed a bug\n* Added feature",

View File

@@ -2,6 +2,7 @@ import * as fs from "node:fs";
import * as path from "node:path";
import { matter } from "lite-matter";
import type { List, ListItem } from "mdast";
import { fromMarkdown } from "mdast-util-from-markdown";
// Regex for filename: YYYY-MM-DD-id.md
@@ -30,19 +31,28 @@ export const VALID_CHANGE_NOTE_CATEGORIES = {
*/
export function isValidChangenoteContent(content: string): boolean {
const ast = fromMarkdown(content);
const lines = content.split("\n");
if (
ast.children.length !== 1 ||
ast.children[0].type !== "list" ||
ast.children[0].ordered === true
) {
return false;
function listHasHyphenBullets(node: List | ListItem): boolean {
if (node.type === "list") {
return node.children.every(listHasHyphenBullets);
}
const line = lines[node.position!.start.line - 1].trim();
return (
line.startsWith("-") &&
node.children.every(
(child) => child.type !== "list" || listHasHyphenBullets(child),
)
);
}
const lines = content.split("\n");
return ast.children[0].children.every((listItem) => {
return lines[listItem.position!.start.line - 1].startsWith("-");
});
return (
ast.children.length === 1 &&
ast.children[0].type === "list" &&
ast.children[0].ordered === false &&
listHasHyphenBullets(ast.children[0])
);
}
/**