Fix radius var fallback detection (#687)

Strip closing var() parentheses before resolving fallback radius tokens, preserving on-scale values and actionable ignore values.

AI-assisted change: implemented with Codex under @pbakaus direction.
This commit is contained in:
Paul Bakaus
2026-08-31 23:27:49 -04:00
committed by GitHub
parent d3f4cc8f4b
commit 1bcdf80f91
2 changed files with 22 additions and 1 deletions
+3 -1
View File
@@ -995,7 +995,9 @@ function extractRadiusTokens(value) {
return String(value || '')
.replace(/\s*\/\s*/g, ' ')
.split(/\s+/)
.map(token => token.trim())
// var() fallbacks leave the closing parenthesis on the final token. Strip
// it before length resolution so `8px)` is not treated as unitless 8rem.
.map(token => token.trim().replace(/\)+$/, ''))
.filter(Boolean);
}
+19
View File
@@ -389,6 +389,25 @@ describe('checkSourceDesignSystem()', () => {
);
});
it('judges var() radius fallbacks without keeping the closing parenthesis', () => {
const designSystem = normalizeDesignSystem({
frontmatter: { rounded: { md: '8px' } },
});
const findings = checkSourceDesignSystem(`
.good {
border-radius: var(--radius-md, 8px);
}
.bad {
border-radius: var(--radius-custom, 18px);
}
`, '/tmp/radius-fallbacks.css', { designSystem });
assert.deepEqual(
findings.map((item) => [item.antipattern, item.ignoreValue]),
[['design-system-radius', '18px']],
);
});
it('strips CSS priority markers before checking font-family declarations', () => {
const designSystem = sampleDesignSystem();
const findings = checkSourceDesignSystem(`