Loading...
Loading...
Compare original and translation side by side
| Metric | Threshold | Penalty |
|---|---|---|
| Cyclomatic Complexity | ≤10 OK, 11-20 warning, >20 fail | -5 (warning), -10 (fail) per function |
| Function size | ≤50 lines OK, >50 warning | -3 per function |
| File size | ≤500 lines OK, >500 warning | -5 per file |
| Nesting depth | ≤3 OK, >3 warning | -3 per instance |
| Parameter count | ≤4 OK, >4 warning | -2 per function |
| 指标 | 阈值 | 扣分项 |
|---|---|---|
| Cyclomatic Complexity(圈复杂度) | ≤10 合格,11-20 警告,>20 不合格 | 每个函数扣5分(警告)、扣10分(不合格) |
| 函数大小 | ≤50行 合格,>50行 警告 | 每个函数扣3分 |
| 文件大小 | ≤500行 合格,>500行 警告 | 每个文件扣5分 |
| 嵌套深度 | ≤3 合格,>3 警告 | 每处扣3分 |
| 参数数量 | ≤4 合格,>4 警告 | 每个函数扣2分 |
Code Quality Score = 100 - metric_penalties - issue_penalties| Severity | Penalty | Examples |
|---|---|---|
| high | -20 | Security vulnerability, O(n²)+ algorithm, N+1 query |
| medium | -10 | DRY violation, suboptimal approach, missing config |
| low | -3 | Naming convention, minor code smell |
| Score | Status | Verdict |
|---|---|---|
| 90-100 | Excellent | PASS |
| 70-89 | Acceptable | CONCERNS |
| <70 | Below threshold | ISSUES_FOUND |
Code Quality Score = 100 - metric_penalties - issue_penalties| 严重程度 | 扣分项 | 示例 |
|---|---|---|
| 高 | -20 | 安全漏洞、O(n²)+级算法、N+1查询 |
| 中 | -10 | 违反DRY原则、方案非最优、缺少配置 |
| 低 | -3 | 命名规范问题、轻微代码异味 |
| 分数 | 状态 | 结论 |
|---|---|---|
| 90-100 | 优秀 | PASS |
| 70-89 | 可接受 | CONCERNS |
| <70 | 低于阈值 | ISSUES_FOUND |
| Prefix | Category | Default Severity | MCP Ref |
|---|---|---|---|
| SEC- | Security (auth, validation, secrets) | high | — |
| PERF- | Performance (algorithms, configs, bottlenecks) | medium/high | ✓ Required |
| MNT- | Maintainability (DRY, SOLID, complexity) | medium | — |
| ARCH- | Architecture (layers, boundaries, patterns) | medium | — |
| BP- | Best Practices (implementation differs from recommended) | medium | ✓ Required |
| OPT- | Optimality (better approach exists for this goal) | medium | ✓ Required |
| Prefix | Category | Severity |
|---|---|---|
| PERF-ALG- | Algorithm complexity (Big O) | high if O(n²)+ |
| PERF-CFG- | Package/library configuration | medium |
| PERF-PTN- | Architectural pattern performance | high |
| PERF-DB- | Database queries, indexes | high |
| 前缀 | 分类 | 默认严重程度 | MCP Ref |
|---|---|---|---|
| SEC- | 安全(认证、验证、密钥) | 高 | — |
| PERF- | 性能(算法、配置、瓶颈) | 中/高 | ✓ 必需 |
| MNT- | 可维护性(DRY、SOLID、复杂度) | 中 | — |
| ARCH- | 架构(分层、边界、模式) | 中 | — |
| BP- | 最佳实践(实现方式与推荐不符) | 中 | ✓ 必需 |
| OPT- | 最优性(存在更适合该目标的方案) | 中 | ✓ 必需 |
| 前缀 | 分类 | 严重程度 |
|---|---|---|
| PERF-ALG- | 算法复杂度(大O表示法) | 若为O(n²)+则为高 |
| PERF-CFG- | 包/库配置 | 中 |
| PERF-PTN- | 架构模式性能 | 高 |
| PERF-DB- | 数据库查询、索引 | 高 |
ref_search_documentation("{goal} approaches comparison {tech_stack} 2026")ref_search_documentation("{chosen_approach} best practices {tech_stack} 2026")query-docs(library_id, "best practices implementation patterns")query-docsref_search_documentation("{pattern} performance bottlenecks")query-docs(orm_library_id, "query optimization")ref_search_documentation("{goal} approaches comparison {tech_stack} 2026")ref_search_documentation("{chosen_approach} best practices {tech_stack} 2026")query-docs(library_id, "best practices implementation patterns")query-docsref_search_documentation("{pattern} performance bottlenecks")query-docs(orm_library_id, "query optimization")verdict: PASS | CONCERNS | ISSUES_FOUND
code_quality_score: {0-100}
metrics:
avg_cyclomatic_complexity: {value}
functions_over_50_lines: {count}
files_over_500_lines: {count}
issues:
# OPTIMALITY
- id: "OPT-001"
severity: medium
file: "src/auth/index.ts"
goal: "User session management"
finding: "Suboptimal approach for session management"
chosen: "Custom JWT with localStorage"
recommended: "httpOnly cookies + refresh token rotation"
reason: "httpOnly cookies prevent XSS token theft"
source: "ref://owasp-session-management"
# BEST PRACTICES
- id: "BP-001"
severity: medium
file: "src/api/routes.ts"
finding: "POST for idempotent operation"
best_practice: "Use PUT for idempotent updates (RFC 7231)"
source: "ref://api-design-guide#idempotency"
# PERFORMANCE - Algorithm
- id: "PERF-ALG-001"
severity: high
file: "src/utils/search.ts:42"
finding: "Nested loops cause O(n²) complexity"
current: "O(n²) - nested filter().find()"
optimal: "O(n) - use Map/Set for lookup"
source: "ref://javascript-performance#data-structures"
# PERFORMANCE - Config
- id: "PERF-CFG-001"
severity: medium
file: "src/db/connection.ts"
finding: "Missing connection pool config"
current_config: "default (pool: undefined)"
recommended: "pool: { min: 2, max: 10 }"
source: "context7://pg#connection-pooling"
# PERFORMANCE - Database
- id: "PERF-DB-001"
severity: high
file: "src/repositories/user.ts:89"
finding: "N+1 query pattern detected"
issue: "users.map(u => u.posts) triggers N queries"
solution: "Use eager loading: include: { posts: true }"
source: "context7://prisma#eager-loading"
# MAINTAINABILITY
- id: "MNT-001"
severity: medium
file: "src/service.ts:42"
finding: "DRY violation: duplicate validation logic"
suggested_action: "Extract to shared validator"verdict: PASS | CONCERNS | ISSUES_FOUND
code_quality_score: {0-100}
metrics:
avg_cyclomatic_complexity: {value}
functions_over_50_lines: {count}
files_over_500_lines: {count}
issues:
# OPTIMALITY
- id: "OPT-001"
severity: medium
file: "src/auth/index.ts"
goal: "User session management"
finding: "Suboptimal approach for session management"
chosen: "Custom JWT with localStorage"
recommended: "httpOnly cookies + refresh token rotation"
reason: "httpOnly cookies prevent XSS token theft"
source: "ref://owasp-session-management"
# BEST PRACTICES
- id: "BP-001"
severity: medium
file: "src/api/routes.ts"
finding: "POST for idempotent operation"
best_practice: "Use PUT for idempotent updates (RFC 7231)"
source: "ref://api-design-guide#idempotency"
# PERFORMANCE - Algorithm
- id: "PERF-ALG-001"
severity: high
file: "src/utils/search.ts:42"
finding: "Nested loops cause O(n²) complexity"
current: "O(n²) - nested filter().find()"
optimal: "O(n) - use Map/Set for lookup"
source: "ref://javascript-performance#data-structures"
# PERFORMANCE - Config
- id: "PERF-CFG-001"
severity: medium
file: "src/db/connection.ts"
finding: "Missing connection pool config"
current_config: "default (pool: undefined)"
recommended: "pool: { min: 2, max: 10 }"
source: "context7://pg#connection-pooling"
# PERFORMANCE - Database
- id: "PERF-DB-001"
severity: high
file: "src/repositories/user.ts:89"
finding: "N+1 query pattern detected"
issue: "users.map(u => u.posts) triggers N queries"
solution: "Use eager loading: include: { posts: true }"
source: "context7://prisma#eager-loading"
# MAINTAINABILITY
- id: "MNT-001"
severity: medium
file: "src/service.ts:42"
finding: "DRY violation: duplicate validation logic"
suggested_action: "Extract to shared validator"references/code_metrics.mddocs/guides/shared/templates/task_template_implementation.mdreferences/code_metrics.mddocs/guides/shared/templates/task_template_implementation.md