fix(design-system): 디자인 검사가 기능 CSS·gradient·인라인 style의 날 값을 잡는다
`check:design-system`이 잡지 못하는 길이 다섯 남았다(1101/12-03, 지금 위반
없음). gradient의 색상각 보간(`linear-gradient(in oklch, …)`)은 UI-02가
`color-mix`만 봐서 지난다. TSX 인라인 `color-mix`도 그렇다. 기능 폴더의 CSS는
아예 읽지 않는다. style sheet에서 `:root`로 토큰을 다시 정의해도, focus ring을
`outline-offset: 0`으로 그려 UI-01의 대비 계산 밖으로 내보내도 지난다. 그리고
primitive의 `className`·`style`이 범위 없이 열려 있어 화면이 primitive 위에
`style={{ color: "red", padding: 13 }}`을 얹어도 막는 것이 없다(04-14).
고른 방법: UI-02 정규식이 gradient의 색 공간까지 보고 TS·TSX 소스에도 돈다.
토큰 파일 밖 CSS는 `src/` 아래 전부를 읽고, 날 색·토큰 재정의·offset 0
focus ring을 거절한다. 04-14는 결정(2026-11-12, 총괄: 공개 props는 두고
검사를 더한다)대로 TSX `style={{ … }}`의 손 색(키워드·`var()` 말고)과 손
간격·글자·반경·층·그림자 값을 거절한다. `className`·`style`의 범위(배치용)를
`docs/styling/design-tokens.md`에 적고, fe-design-system 스킬의 「검사가 안
보는 것」 문장을 새 범위에 맞췄다. 거절 fixture `raw-inline-style.tsx`를
더했다. 버린 대안: primitive 공개 props에서 `style`을 빼기(배럴 표면 BREAKING).
위험·한계: 다운스트림이 기능 CSS나 인라인 style에 날 값을 두었으면 다음
동기화에서 그 줄이 이름과 함께 실패한다. 문자열로 조립한 class와 Tailwind
임의 값은 여전히 보지 않는다.
검증: 규칙 단위 시험, check-design-system 연결 시험(기능 폴더 probe CSS),
`check:design-system:fixture`(FE-GATE-029)는 desktop에서 돌려 PR 본문에 적는다.
Refs: 1101/12-03, 1112/04-14
This commit is contained in:
@@ -16,7 +16,11 @@ import {
|
||||
focusContrastFailures,
|
||||
hueMixFailures,
|
||||
rawSemanticColourFailures,
|
||||
focusOffsetFailures,
|
||||
inlineStyleFailures,
|
||||
rawStyleValueFailures,
|
||||
styleSheetColourFailures,
|
||||
tokenRedefinitionFailures,
|
||||
undeclaredComponentTokenFailures,
|
||||
unreadTokenFailures,
|
||||
} from "./lib/design-system-rules.ts";
|
||||
@@ -44,12 +48,14 @@ for (const [layer, file, tokens] of tokenLayers) {
|
||||
}
|
||||
}
|
||||
|
||||
// theme.css only imports the files under styles/theme/, so check them all.
|
||||
const styleFiles = (
|
||||
await readdir("src/presentation/styles", { recursive: true })
|
||||
)
|
||||
// Every style sheet under src/, not only the ones theme.css imports: a
|
||||
// feature's own CSS is a style sheet too (1101/12-03).
|
||||
const tokenFileSet = new Set<string>(Object.values(tokenFiles));
|
||||
const styleFiles = (await readdir("src", { recursive: true }))
|
||||
.filter((file) => file.endsWith(".css"))
|
||||
.map((file) => path.join("src/presentation/styles", file));
|
||||
.map((file) => path.join("src", file))
|
||||
.filter((file) => !tokenFileSet.has(file))
|
||||
.sort();
|
||||
const cssSources = await Promise.all(
|
||||
[...Object.values(tokenFiles), ...styleFiles].map(
|
||||
async (file) => ({ file, source: await readFile(file, "utf8") }),
|
||||
@@ -67,7 +73,21 @@ for (const { file, source } of cssSources) {
|
||||
}
|
||||
}
|
||||
failures.push(...hueMixFailures({ file, source }));
|
||||
if (styleFiles.includes(file)) failures.push(...rawStyleValueFailures({ file, source }));
|
||||
if (!tokenFileSet.has(file)) {
|
||||
failures.push(
|
||||
...rawStyleValueFailures({ file, source }),
|
||||
...styleSheetColourFailures({ file, source }),
|
||||
...focusOffsetFailures({ file, source }),
|
||||
);
|
||||
}
|
||||
}
|
||||
const tokenNames = new Set(
|
||||
cssSources
|
||||
.filter(({ file }) => tokenFileSet.has(file))
|
||||
.flatMap(({ source }) => [...source.matchAll(/(--[a-z0-9-]+)\s*:/g)].map((match) => match[1])),
|
||||
);
|
||||
for (const { file, source } of cssSources) {
|
||||
if (!tokenFileSet.has(file)) failures.push(...tokenRedefinitionFailures({ file, source }, tokenNames));
|
||||
}
|
||||
|
||||
const semanticSource = await readFile(tokenFiles.semantic, "utf8");
|
||||
@@ -166,6 +186,7 @@ for (const file of sources) {
|
||||
) {
|
||||
failures.push(`raw palette value in ${file}`);
|
||||
}
|
||||
failures.push(...hueMixFailures({ file, source }), ...inlineStyleFailures({ file, source }));
|
||||
if (
|
||||
file.includes("tests/fixtures/design-system/forbidden") &&
|
||||
source.includes("TOOLTIP_ONLY_REQUIRED_INFORMATION")
|
||||
|
||||
@@ -64,10 +64,13 @@ export function focusContrastFailures(
|
||||
// stop such as oklch(1 0 0) carries hue 0: 14% blue into white came out
|
||||
// pink. oklab mixes on straight lines and has no hue to drag. CSS
|
||||
// function names and keywords ignore ASCII case, so OKLCH counts too.
|
||||
// A gradient interpolates the same way (`linear-gradient(90deg in oklch,
|
||||
// …)`), and an inline style in TSX is CSS too (1101/12-03).
|
||||
const HUE_MIX =
|
||||
/(?:color-mix\(\s*|(?:repeating-)?(?:linear|radial|conic)-gradient\([^,()]*?)\bin\s+(oklch|lch|hsl|hwb)\b/gi;
|
||||
|
||||
export function hueMixFailures({ file, source }: CssSource): string[] {
|
||||
const mixes = withoutComments(source).matchAll(
|
||||
/color-mix\(\s*in\s+(oklch|lch|hsl|hwb)\b/gi,
|
||||
);
|
||||
const mixes = withoutComments(source).matchAll(HUE_MIX);
|
||||
return [...mixes].map((match) => `${file} mixes colours in ${match[1]}; use oklab`);
|
||||
}
|
||||
|
||||
@@ -203,3 +206,65 @@ export function rawStyleValueFailures({ file, source }: CssSource): string[] {
|
||||
}
|
||||
return failures;
|
||||
}
|
||||
|
||||
// Outside the token files a style reads colours, it does not define them.
|
||||
// 1101/12-03: a raw colour in a feature's own CSS, a token redefined under
|
||||
// :root in a style sheet (the token file then no longer decides it), and a
|
||||
// focus ring drawn with no offset (UI-01 measures the ring against the
|
||||
// surface around the control, not against the control) all passed.
|
||||
export function styleSheetColourFailures({ file, source }: CssSource): string[] {
|
||||
return [...withoutComments(source).matchAll(/(?<![\w-])([a-z-]+)\s*:\s*([^;{}]+);/g)]
|
||||
.filter((match) => !match[1].startsWith("--") && RAW_COLOUR.test(match[2]))
|
||||
.map((match) => `${file} ${match[1]}: ${match[2].trim()} is a raw colour; read a colour token`);
|
||||
}
|
||||
|
||||
export function tokenRedefinitionFailures(
|
||||
{ file, source }: CssSource,
|
||||
tokens: ReadonlySet<string>,
|
||||
): string[] {
|
||||
return [...withoutComments(source).matchAll(/(?<![\w-])(--[a-z0-9-]+)\s*:/g)]
|
||||
.filter((match) => tokens.has(match[1]))
|
||||
.map((match) => `${file} redefines the token ${match[1]}; change it in the token files`);
|
||||
}
|
||||
|
||||
export function focusOffsetFailures({ file, source }: CssSource): string[] {
|
||||
return [...withoutComments(source).matchAll(/outline-offset\s*:\s*([^;{}]+);/g)]
|
||||
.filter((match) => /^(?:-|0(?:\.0*)?(?:px|rem|em)?\s*$)/.test(match[1].trim()))
|
||||
.map(
|
||||
(match) =>
|
||||
`${file} outline-offset: ${match[1].trim()} draws the focus ring on the control; UI-01 measures it against the surface around the control`,
|
||||
);
|
||||
}
|
||||
|
||||
// 1112/04-14 (decision 2026-11-12). Primitives keep `className` and `style`
|
||||
// open, so a screen can lay a raw colour or spacing over a primitive. An
|
||||
// inline style may place things and read tokens; a colour or a spacing,
|
||||
// type, radius, layer or shadow value written by hand is refused.
|
||||
// The scale values are judged as UI-06 judges a style sheet: an inline
|
||||
// style is the same declaration written in camelCase, and React writes a bare
|
||||
// number as px except for the unitless properties.
|
||||
const INLINE_COLOUR_KEYWORDS = new Set(["transparent", "currentcolor", "inherit", "initial", "unset", "none"]);
|
||||
const INLINE_COLOUR_PROPERTY = /^(?:color|background|fill|stroke)$|Color$/;
|
||||
const INLINE_UNITLESS = new Set(["zIndex", "fontWeight", "lineHeight", "opacity", "flex", "flexGrow", "flexShrink", "order"]);
|
||||
|
||||
export function inlineStyleFailures({ file, source }: CssSource): string[] {
|
||||
const failures: string[] = [];
|
||||
for (const style of source.matchAll(/style=\{\{([\s\S]*?)\}\}/g)) {
|
||||
for (const entry of style[1].matchAll(/([A-Za-z]+)\s*:\s*(`[^`]*`|"[^"]*"|'[^']*'|-?[\d.]+)/g)) {
|
||||
const [, property, written] = entry;
|
||||
const value = written.replace(/^[`"']|[`"']$/g, "").trim();
|
||||
const colour =
|
||||
INLINE_COLOUR_PROPERTY.test(property) &&
|
||||
!/^var\(/.test(value) &&
|
||||
!INLINE_COLOUR_KEYWORDS.has(value.toLowerCase());
|
||||
const css =
|
||||
/^-?[\d.]+$/.test(written) && !INLINE_UNITLESS.has(property) && Number(value) !== 0 ? `${value}px` : value;
|
||||
const scale =
|
||||
handWrittenValues(property.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`), css).length > 0;
|
||||
if (colour || scale) {
|
||||
failures.push(`${file} style ${property}: ${written} is written by hand; read a token or use a primitive variant`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return failures;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user