feat(cli): Add tttk check validator

Statically validate a directory of tttk documents and report structured diagnostics with file/line positions, exit codes, and --json output. Checks cover code-block roles, unresolved content references, tag blocks, element names, links, anchors, and assets. Runs over the same content registry as the app.
This commit is contained in:
2026-09-12 16:38:21 +08:00
parent d1384c2ccc
commit 9def4d17aa
18 changed files with 1638 additions and 1 deletions
+23
View File
@@ -0,0 +1,23 @@
import type { CheckCommandHandler } from "../types.js";
import { formatHuman, formatJson } from "../validate/diagnostics.js";
import { runCheck } from "../validate/index.js";
export const checkCommand: CheckCommandHandler = async (dir, options) => {
let report;
try {
report = runCheck(dir);
} catch (error) {
console.error(error instanceof Error ? error.message : String(error));
process.exitCode = 2;
return;
}
console.log(
options.json ? formatJson(report) : formatHuman(report, options.quiet),
);
const failed =
report.summary.errors > 0 ||
(options.strict && report.summary.warnings > 0);
if (failed) process.exitCode = 1;
};