файл пакета→ .shtukbase/packages/keer-style/checks/radii.ts
checks/radii.ts
35 строк, 2.0 КБ.
Файл как есть в пакете: код и комментарии в нём не переводятся.
- // KS-R02. Radii only from the scale: border-radius takes var(--ds-radius-…) (or the Tailwind/shadcn --radius…
- // built on it), 0 or 50 %; Tailwind `rounded-…` takes a step of the scale, an arbitrary `rounded-[…]` only a radius var.
- import { allowed, classTokens, declarations, run } from './stylelib.ts';
- export const RULE = { id: 'ks-r02', title: 'Corner radius only from the scale' };
- const STEPS = new Set(['', 'none', 'xs', 'sm', 'md', 'lg', 'xl', '2xl', '3xl', '4xl', 'full']);
- const SIDES = /^(?:[a-z0-9-[\]=&_]+:)*!?rounded(?:-(?:t|r|b|l|s|e|tl|tr|br|bl|ss|se|es|ee))?(?:-(.+))?$/;
- /** One part of a radius value is fine: a radius var (or calc on it), 0, 50 %, inherit. */
- export function radiusOk(value: string): boolean {
- const v = value.trim();
- if (/var\(--(?:ds-)?radius/.test(v)) return true; // a token, or calc() derived from one
- return v.split(/[\s/]+/).filter(Boolean).every((p) => /^(0(px|rem|em)?|50%|100%|inherit|initial|unset|revert)$/.test(p));
- }
- export function check(f: { file: string; kind: string; text: string; reduced: string }): string[] {
- const out: string[] = [];
- const hit = (line: number, what: string) => { if (!allowed(f.text, line)) out.push(`${f.file}:${line}: corner radius ${what} is not from the scale — var(--ds-radius-xs|sm|md|lg|xl|round) or rounded-sm|md|lg|xl|full`); };
- if (f.kind === 'css' || f.kind === 'html') {
- for (const d of declarations(f.reduced)) if (/(^|-)radius$/.test(d.prop) && !d.prop.startsWith('--') && !radiusOk(d.value)) hit(d.line, `${d.prop}: ${d.value.trim()}`);
- }
- if (f.kind === 'code' || f.kind === 'html') {
- for (const { token, line } of classTokens(f.reduced)) {
- const m = token.match(SIDES);
- if (!m) continue;
- const step = m[1] ?? '';
- if (step.startsWith('[')) { const inner = step.slice(1, -1).replace(/_/g, ' '); if (!radiusOk(inner)) hit(line, token); }
- else if (!STEPS.has(step)) hit(line, token);
- }
- }
- return [...new Set(out)];
- }
- if (import.meta.main) run(check);