fix(01-design-tokens-rams-foundation): WR-03 audit named colors, modern color functions, text-shadow

This commit is contained in:
araharah-executor
2026-10-22 09:37:38 +08:00
parent 5e95741364
commit ee48e760f8
2 changed files with 123 additions and 3 deletions
+36
View File
@@ -37,6 +37,10 @@
* family (convention: font: var(--type-*)); var()
* shorthands pass; familiesFromShorthand extracts
* the family for the message → flagged (exit 1)
* T11 named color keywords, oklch()/oklab()/lab()/lch()/
* hwb()/color()/color-mix(), text-shadow → flagged
* (exit 1); currentcolor/inherit/transparent stay
* sanctioned
*/
import { spawnSync } from 'node:child_process';
import { existsSync, mkdirSync, readFileSync, symlinkSync, writeFileSync } from 'node:fs';
@@ -179,6 +183,23 @@ writeFileSync(fontShorthand, `/* literal font: shorthand — flagged regardless
.c-font-shorthand-var { font: var(--type-body-md); }
`);
/* T11 — color-evasion gaps (WR-03): named keywords, modern color
* functions, text-shadow — all previously passed the audit unflagged. */
const colorEvasions = join(FIX, 'color-evasions.css');
writeFileSync(colorEvasions, `/* every flagged declaration must be listed; sanctioned keywords pass */
.k-named { color: red; }
.l-oklch { background: oklch(0.6 0.2 30); }
.m-colorfn { fill: color(display-p3 1 0 0); }
.n-hwb { stroke: hwb(90 10% 0); }
.o-lab { border-color: lab(50% 40 60); }
.p-lch { background-color: lch(50% 40 60); }
.q-text-shadow { text-shadow: 0 1px 0 red; }
/* sanctioned: css-wide + currentcolor/transparent stay clean */
.r-ok { color: currentcolor; }
.s-ok { background: transparent; }
.t-ok { outline: 2px solid inherit; }
`);
/* ————— tests ————— */
// T1 — clean stylesheet exits 0
@@ -319,6 +340,21 @@ writeFileSync(fontShorthand, `/* literal font: shorthand — flagged regardless
`out=${r.out.slice(0, 300)}`);
}
// T11 — named colors, modern color functions, text-shadow flagged
{
const r = runAudit([colorEvasions]);
const markers = ['color: red', 'oklch(0.6 0.2 30)', 'color(display-p3 1 0 0)',
'hwb(90 10% 0)', 'lab(50% 40 60)', 'lch(50% 40 60)', 'text-shadow: 0 1px 0 red'];
const missing = markers.filter((m) => !r.out.includes(m));
check('T11 color evasions → exit 1', r.status === 1,
`status=${r.status} error=${r.error}`);
check('T11 every evasion listed', missing.length === 0,
`missing markers: ${missing.join(', ')}`);
check('T11 sanctioned keywords pass (currentcolor/transparent/inherit)',
!/currentcolor/.test(r.out) && !/transparent/.test(r.out) && !/outline: 2px solid inherit/.test(r.out),
`out=${r.out.slice(0, 300)}`);
}
/* ————— report ————— */
console.log(`audit.test: ${passes.length} passed, ${failures.length} failed`);
passes.forEach((p) => console.log(` PASS ${p}`));