package file→ .shtukbase/packages/design-components/checks/uses-exist.ts
checks/uses-exist.ts
18 lines, 838 B.
- // DSC-R02. Every component a header lists in `uses` exists: it has a header somewhere in the libraries, or a page in
- // /design/components (a planned component the authors wrote by hand).
- import { collect, pageIds } from '../lib/project.ts';
- import { report } from '../lib/report.ts';
- export const RULE = { id: 'dsc-r02', title: 'Every used component exists' };
- export function check(root = process.cwd()): string[] {
- const col = collect(root);
- const known = new Set([...col.comps.map((c) => c.id), ...pageIds(root)]);
- const out: string[] = [];
- for (const c of col.comps)
- for (const u of c.header.uses)
- if (!known.has(u)) out.push(`${c.source}: "${c.id}" uses "${u}", and there is no component with that id — fix the id in the header, or add the component`);
- return out;
- }
- if (import.meta.main) report(check());