Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(design-system): DS-10 非 token 操作数归入混合间距

Kirozeng4f0cbbc26296
diff --git a/scripts/__tests__/hardcoded-color-audit.test.mjs b/scripts/__tests__/hardcoded-color-audit.test.mjs
index 91dfaa2e3b..c22ca5346d 100644
--- a/scripts/__tests__/hardcoded-color-audit.test.mjs
+++ b/scripts/__tests__/hardcoded-color-audit.test.mjs
@@ -150,6 +150,8 @@ test('spacing reports distinguish real generated references, unknown variables a
['p-[var(--space-4,var(--space-2))]', 'mixed-spacing-expression'],
['p-[calc(var(--space-4)*2)]', 'mixed-spacing-expression'],
['gap-[calc(var(--space-4)-var(--space-2))]', 'spacing-expression'],
+ ['p-[calc(var(--space-4)_+_env(safe-area-inset-top))]', 'mixed-spacing-expression'],
+ ['p-[calc(min(var(--space-2),var(--space-4)))]', 'mixed-spacing-expression'],
['p-[var(--space-4,var(--missing))]', 'unknown-spacing-reference'],
['p-[env(safe-area-inset-top)]', 'unclassified-spacing'],
['p-[calc(100%-4px)]', 'unclassified-spacing'],
diff --git a/scripts/shared/design-layer-report.mjs b/scripts/shared/design-layer-report.mjs
index 0940a7f631..a88c09561c 100644
--- a/scripts/shared/design-layer-report.mjs
+++ b/scripts/shared/design-layer-report.mjs
@@ -55,12 +55,16 @@ function classifySpacing(value, spacingVariables = getSpacingVariables()) {
reason: 'Contains a variable outside the generated spacing bindings; verify its source, fallbacks and component role. A variable name alone is not approval.' };
}
if (references.length) {
- // A var() fallback is a second value even when it carries no digit
- // (initial, auto, a nested var): recognise it explicitly, never by
- // whether a digit happens to appear in the rest of the expression.
- const mixed = /var\(\s*--[\w-]+\s*,/.test(expression) || /\d/.test(expression.replace(/--[\w-]+/g, ''));
- return { classification: mixed ? 'mixed-spacing-expression' : 'spacing-expression',
- reason: mixed ? 'Combines spacing references with literal values (including fallbacks); review each literal and the component role.'
+ // Pure means registered var() references joined only by calc operators.
+ // Anything left after stripping them — literals, fallbacks, env()/min()
+ // operands — is a non-token operand; detect that residue explicitly
+ // instead of relying on where a digit happens to appear.
+ const residue = expression
+ .replace(/var\(\s*--[\w-]+\s*\)/g, '')
+ .replace(/calc/g, '')
+ .replace(/[-+*/()_,.\s]/g, '');
+ return { classification: residue.length > 0 ? 'mixed-spacing-expression' : 'spacing-expression',
+ reason: residue.length > 0 ? 'Combines spacing references with literals, fallbacks or other non-token operands (env(), min() …); review each operand and the component role.'
: 'Derived spacing expression; verify the calculation and component role. References do not approve the whole expression.' };
}
// Tailwind writes spaces in arbitrary values as underscores: a bare value