mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-03 21:49:46 +08:00
fix(design-system): DS-10 非 token 操作数归入混合间距
复审指出:已登记 token 与非数字来源组合(如 p-[calc(var(--space-4)_+_env(safe-area-inset-top))])时, 数字检测判不到,被归为纯 spacing-expression,而 env() 操作数 既非已验证引用也非字面量,审阅者失去区分。 mixed 判定改为残差检测:剥离已登记 var() 调用、calc 关键字 与纯操作符后,剩余任何内容(字面量、fallback、env()/min() 操作数)都归 mixed-spacing-expression;仅由已登记引用与 calc 操作符构成的表达式保持 spacing-expression,原有数字与 fallback 行为被残差检测完全覆盖。 Signed-off-by: Kirozeng <kirozeng@gmail.com>
This commit is contained in:
@@ -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'],
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user