forked from c-fu/arah2
fix(01-design-tokens-rams-foundation): WR-02 repair familiesFromShorthand + flag literal font: shorthands
This commit is contained in:
+38
-8
@@ -439,8 +439,19 @@ function checkDeclaration(prop, value, tokens) {
|
||||
violations.push(...literalHexViolations(value, tokens));
|
||||
if (prop.startsWith('--')) return violations; // custom property: color literals above are the checkable surface
|
||||
violations.push(...shadowViolations(prop, value));
|
||||
if (prop === 'font-family' || prop === 'font') {
|
||||
if (!/var\(/i.test(value)) violations.push(...fontViolations(prop === 'font' ? familiesFromShorthand(value) : value, tokens));
|
||||
if (prop === 'font') {
|
||||
/* WR-02: a literal font: shorthand embeds unvalidated weight/
|
||||
size/line-height numerics — flag it outright (package convention:
|
||||
font: var(--type-*)), naming the extracted families. */
|
||||
if (!/var\(/i.test(value)) {
|
||||
const families = familiesFromShorthand(value);
|
||||
violations.push(
|
||||
'literal font: shorthand — use font: var(--type-*) (Rams typography tokens)'
|
||||
+ (families ? `; families: ${families}` : ''),
|
||||
);
|
||||
}
|
||||
} else if (prop === 'font-family' && !/var\(/i.test(value)) {
|
||||
violations.push(...fontViolations(value, tokens));
|
||||
}
|
||||
if (RADIUS_PROPS.test(prop) && !radiusAllowed(value)) {
|
||||
violations.push('non-zero border-radius (Rams Shapes: absolute zero roundedness)');
|
||||
@@ -448,13 +459,32 @@ function checkDeclaration(prop, value, tokens) {
|
||||
return violations;
|
||||
}
|
||||
|
||||
/* font: shorthand — families are the comma groups without sizes/weights. */
|
||||
/* font: shorthand — families are the comma groups after the leading
|
||||
style/variant/weight keyword run and the size[/line-height]
|
||||
component: `700 14px/18px Arial, sans-serif` → `Arial, sans-serif`.
|
||||
(WR-02: the old single-strip regex removed only the first token,
|
||||
leaving "14px/18px Arial", which the numeric filter then dropped —
|
||||
so no font: shorthand could ever be flagged.) */
|
||||
function familiesFromShorthand(value) {
|
||||
return value
|
||||
.split(',')
|
||||
.map((g) => g.trim().replace(/^[0-9./]+\S*\s+/g, '').trim())
|
||||
.filter((g) => !/^[0-9.]/.test(g) && g.length > 0)
|
||||
.join(',');
|
||||
const families = [];
|
||||
for (const group of splitTopLevel(value, ',')) {
|
||||
let s = group.trim();
|
||||
if (!s) continue;
|
||||
/* strip the leading style/variant/weight run (any order per the
|
||||
CSS grammar, incl. bare weights and an oblique angle) */
|
||||
let m;
|
||||
while ((m = /^(?:normal|italic|oblique(?:\s+[0-9.]+(?:deg|grad|rad|turn))?|small-caps|bold|bolder|lighter|[1-9][0-9]{0,2})\s+/i.exec(s))) {
|
||||
s = s.slice(m[0].length);
|
||||
}
|
||||
/* strip the mandatory size (optionally /line-height) once */
|
||||
s = s.replace(
|
||||
/^(?:calc\([^()]*\)|[0-9]*\.?[0-9]+(?:[a-z%]+)?)\s*\/\s*(?:calc\([^()]*\)|[0-9]*\.?[0-9]+(?:[a-z%]+)?)\s+/i,
|
||||
'',
|
||||
).replace(/^(?:calc\([^()]*\)|[0-9]*\.?[0-9]+(?:[a-z%]+)?)\s+/i, '');
|
||||
const family = stripFamily(s);
|
||||
if (family) families.push(family);
|
||||
}
|
||||
return families.join(',');
|
||||
}
|
||||
|
||||
/* ————— audit driver ————— */
|
||||
|
||||
Reference in New Issue
Block a user