说明
日常开发当中总会接手别人的项目,项目的水深不深,屎山?如何快速的鉴定? 前一篇已经帮大家鉴定了山,今天就来鉴定shit
干货
鉴定当前项目里的每个文件里的函数超过max行?函数max建议100内吧。
function checkNode(node) {
if (
(node.type === "ObjectMethod" || node.type === "ObjectProperty") &&
node.key &&
node.key.name === "methods" &&
node.value &&
node.value.properties
) {
let methods = [];
node.value.properties.forEach((method) => {
if (method.type === "ObjectMethod" && method.loc) {
const lineCount = getLineCount(method);
methods.push(method.key.name);
if (lineCount > MAX_FUNCTION_LINES) {
const actualLineNumber = method.loc.start.line + templateLineCount;
af_result.push({
filePath,
method: method.key.name,
lineCount,
actualLineNumber,
methods,
});
}
}
});
}
}
注意使用到的插件
const ast = babelParser.parse(scriptContent, {
sourceType: "module",
plugins: ["typescript", "jsx", "decorators-legacy", "classProperties"],
// errorRecovery: true,
});
验证
可找出当前文件下超过200行的函数 可统计methods的长度即为多少个
最后
当然项目是不是屎山还是要多维度的去看。按照权重去配比。但是文件行数和函数过长肯定不是啥好项目吧(sdk除外)。 你觉得的呢?