code-review

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Code Review

代码审查

Review code for quality issues, code smells, and pragmatic programming violations.
审查代码中的质量问题、代码异味以及违反《程序员修炼之道》原则的情况。

Review Modes

审查模式

Mode 1: PR/Diff Review

模式1:PR/差异审查

bash
undefined
bash
undefined

Get changed files

获取变更文件

git diff --name-only <base>..HEAD git diff <base>..HEAD

Focus only on changed lines and their immediate context.
git diff --name-only <base>..HEAD git diff <base>..HEAD

仅关注变更的代码行及其直接上下文。

Mode 2: Full Codebase Audit

模式2:全代码库审计

Scan all source files, prioritizing:
  1. Entry points (main, index, app)
  2. Core business logic
  3. Frequently modified files (
    git log --format='%H' | head -100 | xargs -I{} git diff-tree --no-commit-id --name-only -r {} | sort | uniq -c | sort -rn
    )
扫描所有源文件,优先处理:
  1. 入口文件(main、index、app)
  2. 核心业务逻辑
  3. 频繁修改的文件 (
    git log --format='%H' | head -100 | xargs -I{} git diff-tree --no-commit-id --name-only -r {} | sort | uniq -c | sort -rn
    )

Review Checklist

审查检查清单

1. Code Smells (Critical)

1. 代码异味(严重)

See references/code-smells.md for full catalog.
Bloaters - Code that grows too large
  • Long Method (>20 lines)
  • Large Class (>200 lines)
  • Long Parameter List (>3 params)
  • Primitive Obsession
Object-Orientation Abusers
  • Switch Statements (replace with polymorphism)
  • Refused Bequest
  • Alternative Classes with Different Interfaces
Change Preventers
  • Divergent Change (one class, many reasons to change)
  • Shotgun Surgery (one change, many classes affected)
  • Parallel Inheritance Hierarchies
Dispensables
  • Dead Code
  • Duplicate Code
  • Lazy Class
  • Speculative Generality
Couplers
  • Feature Envy
  • Inappropriate Intimacy
  • Message Chains
  • Middle Man
完整目录请参考 references/code-smells.md
臃肿代码 - 过度膨胀的代码
  • 长方法(超过20行)
  • 大类(超过200行)
  • 长参数列表(超过3个参数)
  • 基本类型偏执
面向对象滥用
  • Switch语句(建议用多态替代)
  • 被拒绝的继承
  • 接口不同的替代类
变更阻碍者
  • 发散式变更(一个类有多个变更理由)
  • 霰弹式修改(一个变更影响多个类)
  • 平行继承层次结构
冗余代码
  • 死代码
  • 重复代码
  • 懒惰类
  • 臆想性通用性
耦合类
  • 特性羡慕
  • 过度亲密
  • 消息链
  • 中间人

2. Pragmatic Programmer Principles

2. 《程序员修炼之道》原则

DRY (Don't Repeat Yourself)
  • Duplicated logic or knowledge
  • Copy-paste code
  • Repeated magic values
Orthogonality
  • Components that should be independent but aren't
  • Changes rippling across unrelated modules
Reversibility
  • Hard-coded decisions that should be configurable
  • Vendor lock-in without abstraction
Tracer Bullets
  • Is the code testable end-to-end?
  • Are there integration points?
Good Enough Software
  • Over-engineering for unlikely scenarios
  • Premature optimization
Broken Windows
  • Commented-out code
  • TODO/FIXME without tickets
  • Inconsistent formatting
DRY(不要重复自己)
  • 重复的逻辑或知识
  • 复制粘贴的代码
  • 重复的魔法值
正交性
  • 本应独立但实际耦合的组件
  • 变更影响到无关模块
可逆性
  • 本应可配置却硬编码的决策
  • 无抽象的供应商锁定
追踪代码
  • 代码是否可端到端测试?
  • 是否有集成点?
足够好的软件
  • 针对不太可能的场景过度设计
  • 过早优化
破窗理论
  • 注释掉的代码
  • 无关联工单的TODO/FIXME
  • 不一致的格式

3. Security & Safety

3. 安全与防护

  • Input validation
  • SQL injection risks
  • XSS vulnerabilities
  • Hardcoded secrets
  • Unsafe deserialization
  • 输入验证
  • SQL注入风险
  • XSS漏洞
  • 硬编码的密钥
  • 不安全的反序列化

4. Maintainability

4. 可维护性

  • Unclear naming
  • Missing or outdated comments
  • Complex conditionals
  • Deep nesting (>3 levels)
  • Missing error handling
  • 命名不清晰
  • 缺失或过时的注释
  • 复杂条件判断
  • 深层嵌套(超过3层)
  • 缺失错误处理

Output Format

输出格式

Generate
CODE_REVIEW.md
:
markdown
undefined
生成
CODE_REVIEW.md
:
markdown
undefined

Code Review Report

代码审查报告

Date: YYYY-MM-DD Scope: [PR #123 | Full Audit] Files Reviewed: N
日期: YYYY-MM-DD 范围: [PR #123 | 全审计] 审查文件数: N

Summary

摘要

SeverityCount
CriticalX
MajorX
MinorX
InfoX
严重程度数量
严重X
主要X
次要X
信息X

Critical Issues

严重问题

[Category]: Issue Title

[分类]: 问题标题

File:
path/to/file.ts:42
Smell: [Code smell name]
Description of the issue.
Before:
language
// problematic code
Suggested Fix:
language
// improved code
文件:
path/to/file.ts:42
异味: [代码异味名称]
问题描述。
修改前:
language
// 有问题的代码
建议修复:
language
// 优化后的代码

Major Issues

主要问题

...
...

Minor Issues

次要问题

...
...

Recommendations

建议

  1. Priority fixes
  2. Refactoring suggestions
  3. Architecture improvements
undefined
  1. 优先修复项
  2. 重构建议
  3. 架构改进
undefined

Severity Levels

严重程度等级

LevelDescriptionAction
CriticalSecurity risks, bugs, data loss potentialMust fix before merge
MajorCode smells, maintainability blockersShould fix soon
MinorStyle, minor improvementsNice to have
InfoSuggestions, alternativesOptional
级别描述操作
严重安全风险、bug、数据丢失风险必须在合并前修复
主要代码异味、可维护性障碍应尽快修复
次要样式、小改进有则更好
信息建议、替代方案可选

Resources

资源

  • references/code-smells.md - Complete catalog of code smells with examples
  • references/code-smells.md - 包含示例的完整代码异味目录