Files
Alfred/eslint-rules/no-empty-function.js
lanyuanxiaoyao ab7b7fb189 fix: 质量修复 — ESLint 规则 TS6 兼容 + catch 注解 + 空函数体注释化 + 后端架构对齐 + 前端红线修复
- enforce-catch-type: 增加 TSUnknownKeyword 判断,消除28个 TS6 假阳性
- no-empty-function: 统一为注释方案,移除测试/生产分支和 eslint-disable 引导
- logger.ts: 空函数体改为注释说明,删除无用 eslint-disable 指令
- 补充15处 catch 子句 : unknown 类型注解
- 清理7个测试文件失效 eslint-disable 指令
- chat/send.ts: 提取 getModelWithProvider DAO,消除直接 Drizzle 操作
- projects/update.ts: 修复死代码+条件逻辑 bug
- providers/update.ts: 补充至少一个字段校验
- 前端: inline style → CSS className, ProviderFormModal whitespace 校验
- 开发文档: 更新 Zod 使用说明(AI SDK 框架级约束)
2026-06-01 23:11:42 +08:00

60 lines
1.8 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export const noEmptyFunction = {
meta: {
type: "problem",
docs: {
description: "禁止空函数体。修复方式在函数体内添加注释说明为何为空实现如接口契约、测试桩、noop。",
},
messages: {
unexpected: "空函数体禁止使用。请在 {} 内添加注释说明原因,例如:/* 实现 Logger 接口契约,有意静默丢弃 */。",
},
schema: [],
},
create(context) {
const sourceCode = context.sourceCode ?? context.getSourceCode();
const allowedFunctionTypes = new Set(["ArrowFunctionExpression", "FunctionDeclaration", "FunctionExpression"]);
function isEmptyBody(body) {
return (
body.type === "BlockStatement" && body.body.length === 0 && sourceCode.getCommentsInside(body).length === 0
);
}
function hasDecorator(node) {
return Array.isArray(node.decorators) && node.decorators.length > 0;
}
function isPrivateOrProtectedConstructor(node) {
if (node.parent?.type !== "MethodDefinition") return false;
if (node.parent.kind !== "constructor") return false;
const accessibility = node.parent.accessibility;
return accessibility === "private" || accessibility === "protected";
}
function isOverrideMethod(node) {
if (node.parent?.type !== "MethodDefinition") return false;
return node.parent.override === true;
}
function check(node) {
if (!allowedFunctionTypes.has(node.type)) return;
if (!isEmptyBody(node.body)) return;
if (hasDecorator(node)) return;
if (isPrivateOrProtectedConstructor(node)) return;
if (isOverrideMethod(node)) return;
context.report({
node,
messageId: "unexpected",
});
}
return {
ArrowFunctionExpression: check,
FunctionDeclaration: check,
FunctionExpression: check,
};
},
};