mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-03 21:49:46 +08:00
fix(design-system): DS-10 间距绑定校验拒绝数组与空映射
审查指出:foundations.css 为数组时 typeof 判定为 object 而放行,
{"foundations":{"css":[]}} 真实 CLI 退出 0;无 space-* 条目的映射
也会让全部间距报告退化为 unknown。校验改为要求非数组 mapping 且
过滤后至少一个 spacing 条目,两类输入均退出 2,健康输入不变,
回归测试补数组与无 spacing 条目断言。
Signed-off-by: Kirozeng <kirozeng@gmail.com>
This commit is contained in:
@@ -233,6 +233,12 @@ test('worktree includes staged, unstaged and untracked source; commit mode exclu
|
||||
// candidates, so the audit itself has to validate the contract it hashes.
|
||||
fs.writeFileSync(path.join(temp,bindings),'{bad json');
|
||||
assert.equal(cli('--base-ref',commit,'--worktree','--report').status,2);
|
||||
// Arrays pass typeof checks yet carry no entries, and a mapping without
|
||||
// space-* foundations silently degrades every spacing report to unknown.
|
||||
fs.writeFileSync(path.join(temp,bindings),'{"foundations":{"css":[]}}');
|
||||
assert.equal(cli('--base-ref',commit,'--worktree','--report').status,2);
|
||||
fs.writeFileSync(path.join(temp,bindings),'{"foundations":{"css":{"text":"semantic.foundations.text-14"}}}');
|
||||
assert.equal(cli('--base-ref',commit,'--worktree','--report').status,2);
|
||||
fs.copyFileSync(path.join(root, bindings), path.join(temp, bindings));
|
||||
fs.appendFileSync(path.join(temp,file), '\nconst spacing = "gap-x-[var(--space-4)]";\n');
|
||||
const reported = cli('--base-ref',commit,'--worktree','--report','--json');
|
||||
|
||||
@@ -7,13 +7,16 @@ let spacingVariables;
|
||||
export function getSpacingVariables() {
|
||||
if (!spacingVariables) {
|
||||
const { foundations } = JSON.parse(readFileSync(new URL('../../packages/design-tokens/src/desktop-bindings.json', import.meta.url), 'utf8'));
|
||||
if (!foundations?.css || typeof foundations.css !== 'object') {
|
||||
throw new Error('Invalid desktop-bindings.json; expected foundations.css spacing bindings');
|
||||
if (!foundations?.css || typeof foundations.css !== 'object' || Array.isArray(foundations.css)) {
|
||||
throw new Error('Invalid desktop-bindings.json; expected foundations.css as a non-array mapping');
|
||||
}
|
||||
spacingVariables = new Set(Object.entries(foundations.css)
|
||||
// Includes component spacing (space-input-lg), not only Tailwind's scale.
|
||||
.filter(([, id]) => id.startsWith('semantic.foundations.space-'))
|
||||
.map(([name]) => `--${name}`));
|
||||
if (!spacingVariables.size) {
|
||||
throw new Error('Invalid desktop-bindings.json; foundations.css has no semantic.foundations.space-* entries');
|
||||
}
|
||||
}
|
||||
return spacingVariables;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user