/** * 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; /** 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}`; }