feat: 新增 validateTaskFormat 校验函数

This commit is contained in:
2026-06-10 08:56:44 +08:00
parent 7d5af32ce5
commit 8e00e2cdf1
2 changed files with 46 additions and 1 deletions

View File

@@ -14,3 +14,22 @@ export function parseTasks(content: string): TaskItem[] {
}
return tasks;
}
export class TaskFormatError extends Error {
constructor(message: string) {
super(message);
this.name = this.constructor.name;
}
}
export function validateTaskFormat(content: string): void {
const tasks = parseTasks(content);
if (tasks.length === 0) {
throw new TaskFormatError("task.md 必须包含至少一个 checkbox 项");
}
for (const task of tasks) {
if (task.text.trim() === "") {
throw new TaskFormatError("task.md 中每个 checkbox 项必须有非空描述");
}
}
}