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:
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Shared context passed to every per-document check.
|
||||
*/
|
||||
|
||||
import { posix } from "path";
|
||||
import type { ContentRegistry } from "../../content-registry.js";
|
||||
import type { DiagnosticSink } from "../diagnostics.js";
|
||||
import type { ScanResult } from "../scan.js";
|
||||
import type { SourceFile } from "../source.js";
|
||||
|
||||
export interface CheckContext {
|
||||
source: SourceFile;
|
||||
scan: ScanResult;
|
||||
/** Display path: relative to the root, posix, no leading slash. */
|
||||
file: string;
|
||||
/** Registry key: posix with a leading slash. */
|
||||
pathKey: string;
|
||||
registry: ContentRegistry;
|
||||
/** Raw contents of every indexable file, keyed like the registry. */
|
||||
index: Record<string, string>;
|
||||
/** Absolute root directory of the check. */
|
||||
rootDir: string;
|
||||
sink: DiagnosticSink;
|
||||
}
|
||||
|
||||
export type Check = (ctx: CheckContext) => void;
|
||||
|
||||
/** Strip the registry key's leading slash for display. */
|
||||
export function displayPath(key: string): string {
|
||||
return key.replace(/^\//, "");
|
||||
}
|
||||
|
||||
/** Resolve a reference written in `pathKey` to a registry key. */
|
||||
export function resolveKey(pathKey: string, ref: string): string {
|
||||
if (ref.startsWith("/")) return posix.normalize(ref);
|
||||
const dir = posix.dirname(pathKey);
|
||||
const joined = posix.normalize(posix.join(dir, ref));
|
||||
return joined.startsWith("/") ? joined : `/${joined}`;
|
||||
}
|
||||
Reference in New Issue
Block a user