iter(g65): verify 校验文档 props 落到实现,并补齐漏记字段
This commit is contained in:
@@ -850,6 +850,39 @@ function checkDemoBundle(anchors) {
|
||||
return issues;
|
||||
}
|
||||
|
||||
/*** 文档字段漂移校验:props 名必须在实现源码里真实出现(改了参数名忘了改文档就会命中) ***/
|
||||
function checkPropsImpl(pkg, comps) {
|
||||
const issues = [];
|
||||
const srcDir = path.join(ROOT, pkg.dir, 'src'); // 实现源码目录
|
||||
if (!fs.existsSync(srcDir)) return issues;
|
||||
const sources = new Map(); // 文件名 → 源码文本
|
||||
for (const name of fs.readdirSync(srcDir)) {
|
||||
if (name.endsWith('.ts')) sources.set(name, fs.readFileSync(path.join(srcDir, name), 'utf8'));
|
||||
}
|
||||
const findImpl = (id) => {
|
||||
const own = sources.get(`${id}.ts`);
|
||||
if (own !== undefined) return own; // 同名文件优先
|
||||
const decl = new RegExp(`export function ${id}\\(`); // 兜底:按导出函数名反查文件
|
||||
for (const text of sources.values()) if (decl.test(text)) return text;
|
||||
return null;
|
||||
};
|
||||
for (const c of comps) {
|
||||
if (!c.id) continue; // 缺 id 由主循环报,这里跳过
|
||||
const tag = `${pkg.name}#${c.id}`;
|
||||
const impl = findImpl(c.id);
|
||||
if (impl === null) {
|
||||
issues.push(`${tag}: 在 ${pkg.dir}/src 下找不到实现(既无同名文件,也没有 export function ${c.id})`);
|
||||
continue;
|
||||
}
|
||||
for (const p of c.props ?? []) {
|
||||
const name = String(p.n ?? '');
|
||||
if (!/^[A-Za-z_$][\w$]*$/.test(name)) continue; // 说明性条目(...children、带括号注记)不参与
|
||||
if (!impl.includes(name)) issues.push(`${tag}: 文档声明了 props「${name}」,实现里找不到该名字(改名后文档未同步)`);
|
||||
}
|
||||
}
|
||||
return issues;
|
||||
}
|
||||
|
||||
/*** 清单一致性校验:组件文档块的 id / props 说明 / demo 锚点必须与代码和演示产物对齐 ***/
|
||||
function cmdVerify() {
|
||||
const issues = [];
|
||||
@@ -867,6 +900,7 @@ function cmdVerify() {
|
||||
if (pkg.type === 'skin-dom') {
|
||||
issues.push(...checkSkinCss(pkg));
|
||||
issues.push(...checkTokenRefs(pkg, tokenVars));
|
||||
issues.push(...checkPropsImpl(pkg, comps));
|
||||
}
|
||||
if (comps.length && !exports.length) issues.push(`${pkg.name}: docs.components 有 ${comps.length} 项但 api.exports 为空`);
|
||||
|
||||
@@ -906,7 +940,7 @@ function cmdVerify() {
|
||||
console.error(`${issues.length} violation(s)`);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log('verify OK (manifest ↔ docs ↔ demo 一致,皮肤无硬编码颜色与未定义令牌,README 组件清单与分组同步,backlog ↔ 留痕一致)');
|
||||
console.log('verify OK (manifest ↔ docs ↔ demo 一致,文档 props 均能落到实现,皮肤无硬编码颜色与未定义令牌,README 组件清单与分组同步,backlog ↔ 留痕一致)');
|
||||
}
|
||||
|
||||
/*** 校验 git 提交信息是否符合 COMMITTING.md 规范(参数为 message 文件路径或直接 message 文本),违规退出码 1 ***/
|
||||
|
||||
Reference in New Issue
Block a user