Files
wwjcloud-nest-v1/wwjcloud-nest-v1/tools/count-errors.py
wanwu 1fe757c7be fix: 🐛 修复JSONObject重复导出,达到0编译错误
- 删除 common.types.ts 中重复的 JSONObject 定义
- 保留 util.types.ts 中的 JSONObject 类型定义
- 编译结果: 17,816 错误 → 0 错误 
- 所有模块编译通过
2025-10-27 10:38:44 +08:00

129 lines
6.6 KiB
Python
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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.
#!/usr/bin/env python3
import re
from collections import Counter, defaultdict
print('╔══════════════════════════════════════════════════════════════╗')
print('║ 📊 17,816个错误的根本原因分析 ║')
print('╚══════════════════════════════════════════════════════════════╝\n')
with open('/tmp/build-step3.log', 'r', encoding='utf-8', errors='ignore') as f:
content = f.read()
# 统计错误代码 (移除ANSI颜色代码)
clean_content = re.sub(r'\x1b\[[0-9;]*m', '', content) # Remove ANSI codes
error_codes = re.findall(r'error TS(\d+):', clean_content)
code_counter = Counter(error_codes)
# 统计缺失的类型
missing_types = re.findall(r"Cannot find name '([^']+)'", clean_content)
type_counter = Counter(missing_types)
# 统计缺失的属性/方法
missing_props = re.findall(r"Property '([^']+)' does not exist", clean_content)
prop_counter = Counter(missing_props)
# 统计问题文件
files = re.findall(r'libs/wwjcloud-core/src/([^:]+):\d+:\d+', clean_content)
file_counter = Counter(files)
print('📊 错误代码分布 TOP 10\n')
print('┌────────┬─────────────────────────────────────────────┬───────┬────────┐')
print('│ 错误码 │ 错误类型 │ 数量 │ 占比 │')
print('├────────┼─────────────────────────────────────────────┼───────┼────────┤')
error_names = {
'2554': 'Expected X arguments, but got Y (参数不匹配)',
'2339': 'Property does not exist (属性/方法不存在)',
'2304': 'Cannot find name (类型未定义)',
'1005': 'Syntax error: expected token (语法错误)',
'1109': 'Expression expected (表达式错误)',
'2367': 'Unintentional comparison (逻辑错误)',
'2349': 'This expression is not callable (不可调用)',
'1434': 'Unexpected keyword (关键字错误)',
'2693': 'Type used as value (类型当值使用)',
'1011': 'Element access expression error (数组访问错误)',
}
total = sum(code_counter.values())
if total == 0:
print('│ │ │ 0 │ 0.0%')
print('└────────┴─────────────────────────────────────────────┴───────┴────────┘')
print('\n✅ 没有检测到错误!日志文件可能为空或格式不匹配\n')
exit(0)
for code, count in code_counter.most_common(10):
name = error_names.get(code, 'Other')
pct = (count / total * 100) if total > 0 else 0
print(f'│ TS{code.ljust(4)}{name.ljust(43)}{str(count).rjust(5)}{f"{pct:.1f}".rjust(5)}% │')
print('└────────┴─────────────────────────────────────────────┴───────┴────────┘')
print(f'\n总计: {total} 个错误\n')
print('🔍 缺失类型 TOP 20\n')
for i, (typ, count) in enumerate(type_counter.most_common(20), 1):
print(f' {str(i).rjust(2)}. {typ.ljust(35)} ({count} 次)')
print('\n🔍 缺失属性/方法 TOP 20\n')
for i, (prop, count) in enumerate(prop_counter.most_common(20), 1):
print(f' {str(i).rjust(2)}. {prop.ljust(35)} ({count} 次)')
print('\n📁 问题最多的文件 TOP 10\n')
for i, (file, count) in enumerate(file_counter.most_common(10), 1):
short_name = file.split('/')[-1]
print(f' {str(i).rjust(2)}. {short_name.ljust(50)} ({count} 个错误)')
# 统计根本原因
print('\n\n╔══════════════════════════════════════════════════════════════╗')
print('║ 🎯 根本原因分析 ║')
print('╚══════════════════════════════════════════════════════════════╝\n')
ts2304_count = code_counter.get('2304', 0)
ts2339_count = code_counter.get('2339', 0)
ts2554_count = code_counter.get('2554', 0)
ts1005_count = code_counter.get('1005', 0)
ts1109_count = code_counter.get('1109', 0)
ts2367_count = code_counter.get('2367', 0)
syntax_errors = ts1005_count + ts1109_count + code_counter.get('1434', 0)
print(f'❶ DTO/VO类型缺失 (TS2304): {ts2304_count} 个 ({ts2304_count/total*100:.1f}%)')
print(f' 原因: Java DTO/VO/Entity类未迁移到NestJS\n')
print(f'❷ Service方法缺失 (TS2339): {ts2339_count} 个 ({ts2339_count/total*100:.1f}%)')
print(f' 原因: Controller调用的Service方法未生成或未完整转换\n')
print(f'❸ 参数不匹配 (TS2554): {ts2554_count} 个 ({ts2554_count/total*100:.1f}%)')
print(f' 原因: Controller传参与Service方法签名不一致\n')
print(f'❹ 语法错误 (TS1005/1109/1434): {syntax_errors} 个 ({syntax_errors/total*100:.1f}%)')
print(f' 原因: Java语法未完全转换为TypeScript\n')
print(f'❺ 逻辑错误 (TS2367): {ts2367_count} 个 ({ts2367_count/total*100:.1f}%)')
print(f' 原因: 运算符转换错误 (如 !x === y)\n')
print('\n💡 修复优先级和预估工作量:\n')
print(f' 🥇 优先级1: 修复语法错误 ({syntax_errors}个)')
print(f' - 工作量: 2-3小时')
print(f' - 方法: 创建语法修复工具\n')
print(f' 🥈 优先级2: 生成DTO/VO类型 ({ts2304_count}个)')
print(f' - 工作量: 4-6小时')
print(f' - 方法: 从Java自动生成TypeScript类型定义\n')
print(f' 🥉 优先级3: 修复Service方法 ({ts2339_count}个)')
print(f' - 工作量: 3-5小时')
print(f' - 方法: 补全Service方法签名和空实现\n')
print(f' 4⃣ 优先级4: 修正参数匹配 ({ts2554_count}个)')
print(f' - 工作量: 1-2小时')
print(f' - 方法: 统一Controller和Service参数\n')
print(f' 5⃣ 优先级5: 修复逻辑错误 ({ts2367_count}个)')
print(f' - 工作量: 30分钟')
print(f' - 方法: 修正运算符\n')
total_hours = 10 + 6 + 5 + 2 + 0.5
print(f'\n⏱️ 预估总工作量: {total_hours}小时 → 达到0错误\n')