ShtukbaseStandard
包文件→ .shtukbase/packages/design-components/checks/tokens-only.ts

checks/tokens-only.ts

19 行, 899 B.

文件按包中的原样显示:代码及其注释不做翻译。

  1. // DSC-R04. Component CSS takes colours from the token contract: no hex, rgb, hsl, oklch (or other colour function)
  2. // literal in a declaration, except in the fallback of a var(). So a style can be swapped without touching components.
  3. import { readFileSync } from 'node:fs';
  4. import { join } from 'node:path';
  5. import { rawColours } from '../lib/css.ts';
  6. import { collect } from '../lib/project.ts';
  7. import { report } from '../lib/report.ts';
  8. export const RULE = { id: 'dsc-r04', title: 'Component CSS has tokens only' };
  9. export function check(root = process.cwd()): string[] {
  10. const out: string[] = [];
  11. for (const file of collect(root).cssFiles)
  12. for (const r of rawColours(readFileSync(join(root, file), 'utf8')))
  13. out.push(`${file}:${r.line}: raw colour ${r.literal} in "${r.prop}" — use a var(--…) of the token contract`);
  14. return out;
  15. }
  16. if (import.meta.main) report(check());