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:
DongHyeonka
2026-11-13 23:27:47 +09:00
parent 838ed410f7
commit 5fa4ebe189
6 changed files with 212 additions and 12 deletions
@@ -0,0 +1,4 @@
// 1112/04-14. A screen lays a raw colour and spacing over an element.
export function RawInlineStyle() {
return <div style={{ color: "red", padding: 13 }}>raw inline style</div>;
}
+104 -1
View File
@@ -1,5 +1,5 @@
import { spawnSync } from "node:child_process";
import { cp, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { cp, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
@@ -9,9 +9,13 @@ import {
FOCUS_RING_BACKGROUNDS,
firstFontFamilyFailures,
focusContrastFailures,
focusOffsetFailures,
hueMixFailures,
inlineStyleFailures,
rawSemanticColourFailures,
rawStyleValueFailures,
styleSheetColourFailures,
tokenRedefinitionFailures,
undeclaredComponentTokenFailures,
unreadTokenFailures,
} from "../../scripts/lib/design-system-rules.ts";
@@ -77,6 +81,22 @@ describe("design system rules", { timeout: childProcessTimeout(3_540) }, () => {
]);
});
// 1101/12-03. A gradient interpolates in its colour space too.
it.each([
"linear-gradient(in oklch, red, blue)",
"linear-gradient(90deg in hsl, red, blue)",
"radial-gradient(circle in lch, red, blue)",
"repeating-conic-gradient(from 0deg in hwb, red, blue)",
])("fails %s", (gradient) => {
expect(hueMixFailures(css(`a { background: ${gradient}; }`))).toHaveLength(1);
});
it("passes a gradient in oklab or without a colour space", () => {
expect(
hueMixFailures(css("a { background: linear-gradient(90deg in oklab, red, blue), linear-gradient(red, blue); }")),
).toEqual([]);
});
it("passes oklab, and old code left in a comment", () => {
expect(
hueMixFailures(
@@ -228,6 +248,74 @@ describe("design system rules", { timeout: childProcessTimeout(3_540) }, () => {
});
});
// 1101/12-03. Style sheets read colours; the token files define them.
describe("style sheets outside the token files", () => {
it("fails a raw colour, and passes a token read or a mix of tokens", () => {
expect(
styleSheetColourFailures(css(".a { color: #ff0000; border-color: rgb(1 2 3); }\n.b { color: var(--color-content); background: color-mix(in oklab, var(--color-panel) 92%, transparent); }")),
).toEqual([
"probe.css color: #ff0000 is a raw colour; read a colour token",
"probe.css border-color: rgb(1 2 3) is a raw colour; read a colour token",
]);
});
it("fails a token redefined in a style sheet, and passes a local property", () => {
expect(
tokenRedefinitionFailures(css(":root { --font-sans: serif; }\n.a { --local-gap: 1px; }"), new Set(["--font-sans"])),
).toEqual(["probe.css redefines the token --font-sans; change it in the token files"]);
});
it.each(["0", "0px", "-1px"])("fails a focus ring drawn with outline-offset %s", (offset) => {
expect(focusOffsetFailures(css(`.a:focus-visible { outline-offset: ${offset}; }`))).toEqual([
`probe.css outline-offset: ${offset} draws the focus ring on the control; UI-01 measures it against the surface around the control`,
]);
});
it("passes a focus ring drawn away from the control", () => {
expect(focusOffsetFailures(css(".a:focus-visible { outline-offset: 0.1875rem; }"))).toEqual([]);
});
});
// 1112/04-14. Primitives keep className and style open (decision
// 2026-11-12); the check refuses raw values laid over them.
describe("inline styles in TSX", () => {
it("fails a colour or a scale value written by hand", () => {
expect(
inlineStyleFailures({
file: "probe.tsx",
source: `<Button style={{ color: "red", padding: 13, borderRadius: "4px", zIndex: 5 }} />`,
}),
).toEqual([
'probe.tsx style color: "red" is written by hand; read a token or use a primitive variant',
"probe.tsx style padding: 13 is written by hand; read a token or use a primitive variant",
'probe.tsx style borderRadius: "4px" is written by hand; read a token or use a primitive variant',
"probe.tsx style zIndex: 5 is written by hand; read a token or use a primitive variant",
]);
});
it("judges the scale values as UI-06 does, and every colour property", () => {
expect(
inlineStyleFailures({
file: "probe.tsx",
source: `<div style={{ margin: "0 auto", zIndex: -1, lineHeight: 1, borderTopColor: "red", fontWeight: 700 }} />`,
}),
).toEqual([
'probe.tsx style borderTopColor: "red" is written by hand; read a token or use a primitive variant',
"probe.tsx style fontWeight: 700 is written by hand; read a token or use a primitive variant",
]);
});
it("passes token reads, keywords, zero and layout", () => {
expect(
inlineStyleFailures({
file: "probe.tsx",
source:
"<div style={{ backgroundColor: `var(${token})`, color: \"currentColor\", margin: 0, padding: \"var(--space-2)\", gridColumn: \"1 / 3\", width: 120 }} />",
}),
).toEqual([]);
});
});
describe("UI-05 first font family", () => {
it("fails a named font that nothing loads", () => {
expect(firstFontFamilyFailures("Inter, system-ui, sans-serif", [])).toEqual([
@@ -295,6 +383,17 @@ describe("design system rules", { timeout: childProcessTimeout(3_540) }, () => {
path.join(root, "src/presentation/styles/theme/probe.css"),
".probe { color: color-mix(in oklch, red, blue); }\n",
);
await mkdir(path.join(root, "src/features/probe"), { recursive: true });
await writeFile(
path.join(root, "src/features/probe/probe.css"),
[
".probe-a { color: #ff0000; }",
".probe-b { background: linear-gradient(in oklch, var(--color-action), var(--color-panel)); }",
".probe-c:focus-visible { outline-offset: 0; }",
":root { --font-sans: serif; }",
"",
].join("\n"),
);
const result = spawnSync(process.execPath, [path.resolve("scripts/check-design-system.ts")], {
cwd: root,
@@ -311,6 +410,10 @@ describe("design system rules", { timeout: childProcessTimeout(3_540) }, () => {
/^--font-sans starts with "Inter", which is neither a generic family, loaded by @font-face, nor listed in PRODUCT_LOADED_FONT_FAMILIES$/,
/^src\/presentation\/styles\/theme\/shell\.css:\d+ z-index: 50 writes 50 by hand; read a token \(docs\/styling\/design-tokens\.md UI-06\)$/,
/^semantic token --layer-navigation is defined but no style reads it$/,
/^src\/features\/probe\/probe\.css color: #ff0000 is a raw colour; read a colour token$/,
/^src\/features\/probe\/probe\.css mixes colours in oklch; use oklab$/,
/^src\/features\/probe\/probe\.css outline-offset: 0 draws the focus ring on the control; UI-01 measures it against the surface around the control$/,
/^src\/features\/probe\/probe\.css redefines the token --font-sans; change it in the token files$/,
/^src\/presentation\/design-system\/tokens\/component\.css defines --probe-unlisted, which REQUIRED_COMPONENT_TOKENS in token-contract\.ts does not list$/,
/^src\/presentation\/design-system\/tokens\/semantic\.css --color-danger-surface is the raw colour oklch\(0\.96 0\.035 25\); name it in primitive\.css and read it with var\(\)$/,
];