ShtukbaseStandard
archivo del paquete→ .shtukbase/packages/shadcn/checks/folder.ts

checks/folder.ts

34 líneas, 1.8 KB.

El archivo tal como está en el paquete: el código y sus comentarios no se traducen.

  1. // SHD-R02. Components live in one folder — the `ui` alias of components.json:
  2. // every component placed (.shadcn.json) is there; a file elsewhere does not define a ui component (data-slot="…")
  3. // and does not import Radix primitives (radix-ui, @radix-ui/*) — screens use the components of the folder.
  4. import { existsSync } from 'node:fs';
  5. import { join } from 'node:path';
  6. import { lineAt, projectFiles, read, report } from '../../design-base/lib/files.ts';
  7. import { components, index, readManifest, targets } from '../actions/shadcnlib.ts';
  8. export const RULE = { id: 'shd-r02', title: 'Components in one folder' };
  9. export function check(root = process.cwd()): string[] {
  10. const placed = readManifest(root);
  11. const { cfg } = components(root);
  12. if (!placed || !cfg) return []; // nothing placed, or no config: SHD-R01 says so
  13. const t = targets(cfg, root);
  14. const out: string[] = [];
  15. const items = index();
  16. for (const n of placed.components) {
  17. const file = items[n]?.file;
  18. if (file && !existsSync(join(root, t.ui, file))) out.push(`${t.ui}/${file}: component ${n} is missing from the folder — restore it: shtuk run shadcn place`);
  19. }
  20. const inside = (rel: string) => rel === t.ui || rel.startsWith(`${t.ui}/`);
  21. for (const rel of projectFiles(['tsx', 'jsx', 'ts', 'js'])) {
  22. if (inside(rel)) continue;
  23. const text = read(rel, root);
  24. const radix = /from\s+["'](radix-ui|@radix-ui\/[\w-]+)["']/.exec(text);
  25. if (radix) out.push(`${rel}:${lineAt(text, radix.index)}: import of ${radix[1]} outside the components folder ${t.ui}/ — use the component from there or put a new one there`);
  26. const slot = /data-slot=["'][\w-]+["']/.exec(text);
  27. if (slot) out.push(`${rel}:${lineAt(text, slot.index)}: UI component (${slot[0]}) outside the folder ${t.ui}/ — move it there`);
  28. }
  29. return out;
  30. }
  31. if (import.meta.main) report(check());