fix(design-system): DS-10 间距报告纳入任意 margin 与多值裸值

复审两点:Desktop renderer 新增 mt-[3px]、mx-[7px] 等任意
margin 时完全不匹配,同一 TAILWIND_SPACING 尺度的硬编码间距
整类漏报(仓内存量 69 处);多值任意值(如 p-[14px_16px])
被单值正则归入 unclassified-spacing,无法与真正解析不了的
动态表达式区分。

pattern 增加 m/mx/my/mt/mr/mb/ml/ms/me 进同一分类链;
literal 判定支持下划线分隔的裸值列表并逐项校验数字与单位,
calc(100%-4px) 等无 var 表达式保持 unclassified。

Signed-off-by: Kirozeng <kirozeng@gmail.com>
This commit is contained in:
Kirozeng
2026-09-14 13:05:51 +08:00
parent bfe99b387b
commit 12987f2c92
2 changed files with 16 additions and 4 deletions

View File

@@ -152,6 +152,15 @@ test('spacing reports distinguish real generated references, unknown variables a
['gap-[calc(var(--space-4)-var(--space-2))]', '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'],
['mt-[var(--space-4)]', 'spacing-source-reference'],
['ms-[var(--space-4,initial)]', 'mixed-spacing-expression'],
['mt-[3px]', 'literal-spacing'],
['mx-[7px]', 'literal-spacing'],
['me-[13px]', 'literal-spacing'],
['p-[14px_16px]', 'literal-spacing'],
['px-[8px_12px]', 'literal-spacing'],
['p-[-14px_-16px]', 'literal-spacing'],
]) {
const source = `<div className="${value}" />`;
const [hit] = inspect(file, source);
@@ -163,7 +172,7 @@ test('spacing reports distinguish real generated references, unknown variables a
assert.match(hit.suggestion, /foundations.spacing/);
assert.doesNotMatch(hit.suggestion, /radius overrides/);
}
for (const value of ['p-4', 'gap-x-2', 'gap-y-2', 'gapx-[13px]', 'gapy-[13px]']) {
for (const value of ['p-4', 'm-4', 'mt-2', 'gap-x-2', 'gap-y-2', 'gapx-[13px]', 'gapy-[13px]']) {
assert.deepEqual(inspect(file, `<div className="${value}" />`), [], value);
}
const source = '// gap-x-[13px]\n<div className="gap-x-[13px]" />\n<div className="p-[var(--space-4)]" />';

View File

@@ -63,7 +63,10 @@ function classifySpacing(value, spacingVariables = getSpacingVariables()) {
reason: mixed ? 'Combines spacing references with literal values (including fallbacks); review each literal and the component role.'
: 'Derived spacing expression; verify the calculation and component role. References do not approve the whole expression.' };
}
return { classification: /^-?(?:\d*\.)?\d+(?:px|rem|em|%|vh|vw)?$/.test(expression) ? 'literal-spacing' : 'unclassified-spacing',
// Tailwind writes spaces in arbitrary values as underscores: a bare value
// may be a list (p-[14px_16px]). Every item must be a literal on its own.
const literal = /^-?(?:\d*\.)?\d+(?:px|rem|em|%|vh|vw)?$/;
return { classification: expression.split('_').every(part => literal.test(part)) ? 'literal-spacing' : 'unclassified-spacing',
reason: 'No verified spacing source reference; use the matching standard spacing class or document the component-specific geometry.' };
}
@@ -86,7 +89,7 @@ export function classifyDesignLayer({ member, layer, radius, evidence = false })
export function reportDesignLayers(file, source, changed, locate, spacingVariables) {
const findings = [];
const patterns = /\brounded(?:-(?:\[[^\]\n]+\]|[\w-]+))?|\bborder(?:-radius|Radius)\s*:\s*[^;,}\n]+|\b(?:p[xytrblse]?|gap(?:-[xy])?)-\[[^\]\n]+\]/g;
const patterns = /\brounded(?:-(?:\[[^\]\n]+\]|[\w-]+))?|\bborder(?:-radius|Radius)\s*:\s*[^;,}\n]+|\b(?:[pm][xytrblse]?|gap(?:-[xy])?)-\[[^\]\n]+\]/g;
for (const match of source.matchAll(patterns)) {
const pos = locate(match.index);
if (!changed.has(pos.line)) continue;
@@ -110,7 +113,7 @@ export function reportDesignLayers(file, source, changed, locate, spacingVariabl
value: match[0], disposition: 'report', ...judgement,
suggestion: isRadius
? 'Review the visible frame, contained mark and hit/indicator layers separately against DESIGN §5 and governance §13; register missing evidence/decisions. Do not change user radius overrides.'
: 'Use the existing p/px/py/gap/gap-x/gap-y scale from desktop-bindings.json foundations.spacing and the component treatment in DESIGN §4/5. Verify unknown variables, calculations and fallbacks; do not infer button padding from a DOM tag.' });
: 'Use the existing p/px/py, m/mx/my and gap/gap-x/gap-y scales from desktop-bindings.json foundations.spacing and the component treatment in DESIGN §4/5. Verify unknown variables, calculations and fallbacks; do not infer button spacing from a DOM tag.' });
}
if (/components\/settings\/.*(?:Dialog|Wizard)\.tsx$/.test(file) && changed.size) {
findings.push({ file, line: Math.min(...changed), column: 1, rule: 'form-adoption', disposition: 'report',