файл пакета→ .shtukbase/packages/shtukbase-ui-react/checks/states.ts
checks/states.ts
29 строк, 1.4 КБ.
Файл как есть в пакете: код и комментарии в нём не переводятся.
- // SBR-R02. Every component of the library folder has a states file: next to `<name>.tsx` lies `<name>.states.tsx`
- // that exports `meta` and `states`. Looked at: the component folders of the target (primitives, composites, blocks and any
- // folder the project adds there), except lib/, styles/ and test, story and states files themselves.
- import { existsSync, readFileSync } from 'node:fs';
- import { join } from 'node:path';
- import { componentFiles, config, readManifest } from '../actions/kitlib.ts';
- export const RULE = { id: 'sbr-r02', title: 'A component has a states file' };
- export function check(root = process.cwd()): string[] {
- const { target } = config(root);
- if (!readManifest(root, target)) return []; // not placed: SBR-R01 says so
- const out: string[] = [];
- for (const rel of componentFiles(join(root, target))) {
- const states = rel.replace(/\.tsx$/, '.states.tsx');
- const p = join(root, target, states);
- if (!existsSync(p)) { out.push(`${target}/${rel}: no states file ${states} — describe meta and states (default and its own)`); continue; }
- const text = readFileSync(p, 'utf8');
- if (!/export\s+const\s+meta\b/.test(text) || !/export\s+const\s+states\b/.test(text))
- out.push(`${target}/${states}: the states file has no export const meta or export const states`);
- }
- return out;
- }
- if (import.meta.main) {
- const out = check();
- if (out.length) console.log(out.join('\n'));
- process.exitCode = out.length ? 1 : 0;
- }