mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-03 21:49:46 +08:00
fix(design-system): DS-10 裸间距单位按 CSS 维度语法识别
复审指出:p-[1lh]、mt-[2dvh]、gap-[1cqw]、p-[12PX] 被单位 白名单归入 unclassified-spacing,而排版门禁 (typographyDiscipline.test.ts)已明确认可 dvh/lh/cqw/pt 与 大写单位,且其原则就是数字开头的现代单位不得依赖单位枚举。 literal 判定改为数字加任意字母单位或 %(大小写不敏感), 单值与下划线多值同口径;env()/calc()/字号关键字等非数字 开头的表达式保持 unclassified-spacing。 Signed-off-by: Kirozeng <kirozeng@gmail.com>
This commit is contained in:
@@ -165,6 +165,12 @@ test('spacing reports distinguish real generated references, unknown variables a
|
||||
['p-[14px_16px]', 'literal-spacing'],
|
||||
['px-[8px_12px]', 'literal-spacing'],
|
||||
['p-[-14px_-16px]', 'literal-spacing'],
|
||||
['p-[1lh]', 'literal-spacing'],
|
||||
['mt-[2dvh]', 'literal-spacing'],
|
||||
['gap-[1cqw]', 'literal-spacing'],
|
||||
['p-[12PX]', 'literal-spacing'],
|
||||
['p-[17pt]', 'literal-spacing'],
|
||||
['p-[1lh_2dvh]', 'literal-spacing'],
|
||||
]) {
|
||||
const source = `<div className="${value}" />`;
|
||||
const [hit] = inspect(file, source);
|
||||
|
||||
@@ -68,8 +68,10 @@ function classifySpacing(value, spacingVariables = getSpacingVariables()) {
|
||||
: '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
|
||||
// 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)?$/;
|
||||
// may be a list (p-[14px_16px]). Every item must be a literal on its own —
|
||||
// a number with any CSS dimension unit (1lh, 2dvh, 12PX, 17pt …), never a
|
||||
// unit enumeration, mirroring the typography gate's own discipline.
|
||||
const literal = /^-?(?:\d*\.)?\d+[a-z%]*$/i;
|
||||
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.' };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user