code-review

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Code Review Skill

代码审查Skill

Comprehensive code review skill that combines PR review, self-review, and quality checks.
这是一款结合PR审查、自审查和质量检查的综合性代码审查Skill。

Usage

使用方法

/code-review                # Self-review: current branch vs main
/code-review <branch>       # Self-review: current branch vs specified branch
/code-review pr <number>    # PR review: review the specified PR
The argument is available as
$ARGUMENTS
.
/code-review                # Self-review: current branch vs main
/code-review <branch>       # Self-review: current branch vs specified branch
/code-review pr <number>    # PR review: review the specified PR
参数可通过
$ARGUMENTS
获取。

Argument Parsing

参数解析

$ARGUMENTS parsing:
- Empty → Self-review mode (base=main)
- "pr <number>" → PR review mode (use gh pr diff)
- Otherwise → Self-review mode (base=specified branch)

$ARGUMENTS parsing:
- Empty → Self-review mode (base=main)
- "pr <number>" → PR review mode (use gh pr diff)
- Otherwise → Self-review mode (base=specified branch)

Review Process

审查流程

IMPORTANT: Use Serena MCP extensively to analyze code efficiently while minimizing token consumption.
CRITICAL: Before starting any code review, you MUST read and understand the implementation guidelines:
  • Read
    @~/.claude/templates/frontend-implementation-guidelines.md
    for frontend code reviews
  • Read
    @~/.claude/templates/backend-implementation-guidelines.md
    for backend code reviews
  • Apply the specific principles from these guidelines during your review
重要提示:请广泛使用Serena MCP以高效分析代码,同时减少token消耗。
关键要求:在开始任何代码审查之前,您必须阅读并理解实现指南:
  • 前端代码审查请阅读
    @~/.claude/templates/frontend-implementation-guidelines.md
  • 后端代码审查请阅读
    @~/.claude/templates/backend-implementation-guidelines.md
  • 审查过程中需遵循这些指南中的特定原则

Step 1: Get Changes

步骤1:获取变更内容

For Self-Review (no args or branch name):
bash
undefined
自审查(无参数或指定分支名):
bash
undefined

Get current branch name

Get current branch name

git branch --show-current
git branch --show-current

Determine base branch (use main if $ARGUMENTS is empty, otherwise use $ARGUMENTS)

Determine base branch (use main if $ARGUMENTS is empty, otherwise use $ARGUMENTS)

BASE_BRANCH=${ARGUMENTS:-main}
BASE_BRANCH=${ARGUMENTS:-main}

Get list of changed files

Get list of changed files

git diff $BASE_BRANCH...HEAD --name-status
git diff $BASE_BRANCH...HEAD --name-status

Get commit history

Get commit history

git log $BASE_BRANCH..HEAD --oneline
git log $BASE_BRANCH..HEAD --oneline

Get detailed diff

Get detailed diff

git diff $BASE_BRANCH...HEAD

**For PR Review (`pr <number>`):**
```bash
git diff $BASE_BRANCH...HEAD

**PR审查(`pr <number>`):**
```bash

Get PR information

Get PR information

gh pr view <number>
gh pr view <number>

Get PR diff

Get PR diff

gh pr diff <number>
undefined
gh pr diff <number>
undefined

Step 2: Quality Check (All Files)

步骤2:质量检查(所有文件)

Perform quality checks on all changed files before detailed review:
Code Quality:
  1. Detect unused code (variables, parameters, functions, classes)
  2. Detect commented-out code blocks
  3. Detect unreachable code branches
Comment Quality:
  1. Detect progress/completion declarations ("implemented", "done", etc.)
  2. Detect date or version references in comments
Detection Methods:
  • Use
    mcp__serena__get_symbols_overview
    to get symbol list
  • Use
    mcp__serena__find_referencing_symbols
    to check reference count (0 = unused candidate)
  • Use
    Grep
    for pattern matching:
    • /\/\/.*?(実装済み|done|完了|implemented)/i
    • /\/\/.*?\d{4}[-\/]\d{1,2}[-\/]\d{1,2}/
    • Consecutive commented-out lines (3+ lines)
在详细审查之前,对所有变更文件执行质量检查:
代码质量:
  1. 检测未使用的代码(变量、参数、函数、类)
  2. 检测被注释掉的代码块
  3. 检测不可达的代码分支
注释质量:
  1. 检测进度/完成声明(如"implemented"、"done"等)
  2. 检测注释中的日期或版本引用
检测方法:
  • 使用
    mcp__serena__get_symbols_overview
    获取符号列表
  • 使用
    mcp__serena__find_referencing_symbols
    检查引用计数(0 = 未使用候选)
  • 使用Grep进行模式匹配:
    • /\/\/.*?(実装済み|done|完了|implemented)/i
    • /\/\/.*?\d{4}[-\/]\d{1,2}[-\/]\d{1,2}/
    • 连续3行及以上的注释代码

Step 3: Read Implementation Guidelines

步骤3:阅读实现指南

Based on file extensions in the changes:
  • .ts
    ,
    .tsx
    ,
    .js
    ,
    .jsx
    ,
    .vue
    ,
    .svelte
    → Read frontend guidelines
  • .py
    ,
    .go
    ,
    .java
    ,
    .rs
    ,
    .cs
    → Read backend guidelines
  • Both present → Read both guidelines
根据变更文件的扩展名:
  • .ts
    .tsx
    .js
    .jsx
    .vue
    .svelte
    → 阅读前端指南
  • .py
    .go
    .java
    .rs
    .cs
    → 阅读后端指南
  • 同时存在两类文件 → 阅读两类指南

Step 4: Analyze Each Change

步骤4:分析每项变更

For each changed file:
  1. Get symbol overview: Use
    mcp__serena__get_symbols_overview
  2. Identify changed symbols: Use
    mcp__serena__find_symbol
    for details
  3. Get original code: Use
    git show <base-branch>:path/to/file
  4. Check impact: Use
    mcp__serena__find_referencing_symbols
  5. Review related tests: Check test file changes
对每个变更文件:
  1. 获取符号概览:使用
    mcp__serena__get_symbols_overview
  2. 识别变更符号:使用
    mcp__serena__find_symbol
    查看详情
  3. 获取原始代码:使用
    git show <base-branch>:path/to/file
  4. 检查影响范围:使用
    mcp__serena__find_referencing_symbols
  5. 审查相关测试:检查测试文件的变更

Step 5: Impact Analysis

步骤5:影响分析

Use
find_referencing_symbols
to investigate indirect impacts:
  • Direct impact: List changed functions, APIs, screens
  • Indirect impact: Identify callers/callees
  • Breaking change risks: Type changes, return value changes, exception changes, state management changes, DB schema changes, cache changes
使用
find_referencing_symbols
调查间接影响:
  • 直接影响:列出变更的函数、API、页面
  • 间接影响:识别调用方/被调用方
  • 破坏性变更风险:类型变更、返回值变更、异常变更、状态管理变更、数据库 schema 变更、缓存变更

Step 6: Generate Review Report

步骤6:生成审查报告

Save the review results to
.tmp/code-review-<branch-or-pr>.md

将审查结果保存至
.tmp/code-review-<branch-or-pr>.md

Output Format

输出格式

Write the review in Japanese using the following format:
markdown
undefined
请使用以下格式以中文撰写审查报告:
markdown
undefined

コードレビュー: <ブランチ名 または PR番号>

代码审查:<分支名 或 PR编号>

概要

概要

[変更の目的と範囲の要約]

[变更的目的与范围摘要]

Quality Check結果

质量检查结果

未使用コードの検出

未使用代码检测

ファイル種類詳細
path/to/file.ts42未使用変数
unusedVar
文件行号类型详情
path/to/file.ts42未使用变量
unusedVar

不適切なコメントの検出

不恰当注释检测

ファイル内容
path/to/file.ts15"実装済み"
(問題なければ「問題なし」と記載)

文件行号内容
path/to/file.ts15"已实现"
(若无问题则填写"无问题")

修正1: [修正の概要タイトル]

修正1:[修正概要标题]

背景・実装の意図

背景与实现意图

[修正が必要になった背景と、このアプローチを選んだ理由]
[需要修正的背景,以及选择此方案的理由]

ファイルと関数

文件与函数

  • ファイル:
    path/to/file.ts
  • 関数:
    functionName(args): returnType
  • 文件
    path/to/file.ts
  • 函数
    functionName(args): returnType

変更内容

变更内容

diff
- // 修正前
+ // 修正後
diff
- // 修正前
+ // 修正后

妥当性評価

妥当性评估

観点評価詳細
目的OK / Needs Review / Problem説明
ロジックOK / Needs Review / Problem説明
エラーハンドリングOK / Needs Review / Problem説明
互換性OK / Needs Review / Problem説明
パフォーマンスOK / Needs Review / Problem説明
维度评价详情
目的通过 / 需要审查 / 存在问题说明
逻辑通过 / 需要审查 / 存在问题说明
错误处理通过 / 需要审查 / 存在问题说明
兼容性通过 / 需要审查 / 存在问题说明
性能通过 / 需要审查 / 存在问题说明

テストの有無

测试覆盖情况

テストケース状態ファイル
[テストの説明]Yes / Nopath/to/test.ts
测试用例状态文件
[测试说明]是 / 否path/to/test.ts

懸念事項

注意事项

  • [懸念点があれば記載、なければ「なし」]

(修正ごとに繰り返し)

  • [若有疑虑则填写,若无则填写"无"]

(每个修正项重复上述结构)

波及範囲分析

影响范围分析

直接影響

直接影响

  • [変更された関数、API、画面のリスト]
  • [变更的函数、API、页面列表]

間接影響

间接影响

  • [find_referencing_symbolsで検出した呼び出し元/先]
  • [通过find_referencing_symbols检测到的调用方/被调用方]

破壊的変更の可能性

破坏性变更可能性

  • 型変更
  • 戻り値変更
  • 例外変更
  • 状態管理変更
  • DBスキーマ変更
  • キャッシュ変更
  • 类型变更
  • 返回值变更
  • 异常变更
  • 状态管理变更
  • 数据库Schema变更
  • 缓存变更

不確実性(推測箇所)

不确定性(推测内容)

  • [調査が完全でない部分、推測に基づく発見]

  • [未完全调查的部分,基于推测的发现]

落とし穴チェックリスト

风险点检查清单

セキュリティ

安全性

  • 認可チェック
  • 入力バリデーション
  • ログ出力(機密情報漏洩なし)
  • シークレット管理
  • 权限校验
  • 输入验证
  • 日志输出(无敏感信息泄露)
  • 密钥管理

パフォーマンス

性能

  • N+1クエリ
  • メモリ使用量
  • 同期I/O
  • キャッシュ戦略
  • N+1查询
  • 内存使用量
  • 同步I/O
  • 缓存策略

例外処理

异常处理

  • リトライロジック
  • 外部I/Oタイムアウト
  • 重试逻辑
  • 外部I/O超时

互換性

兼容性

  • 公開API
  • イベント
  • データベーススキーマ

  • 公开API
  • 事件
  • 数据库Schema

追加すべきテストケース

应补充的测试用例

必須

必须补充

  1. [追加必須のテスト]
  1. [必须补充的测试]

推奨

建议补充

  1. [あると良いテスト]
  1. [建议补充的测试]

エッジケース

边缘场景

  1. [テストすべきエッジケース]

  1. [需测试的边缘场景]

実装ガイドライン準拠性

实现指南合规性

Frontend(該当する場合)

前端(适用时)

原則準拠コメント
1. 関心の分離(カスタムフック)○/△/×
2. エラーハンドリング○/△/×
3. ローディング状態管理○/△/×
4. メモ化によるパフォーマンス最適化○/△/×
5. TypeScript型安全性○/△/×
6. コンポーネント分解○/△/×
7. 宣言的UIデザイン○/△/×
8. 集中データ管理○/△/×
9. 定数の外部化○/△/×
10. Props Drilling回避○/△/×
原则合规性备注
1. 基于自定义Hook的关注点分离是/部分/否
2. 错误处理是/部分/否
3. 加载状态管理是/部分/否
4. 基于记忆化的性能优化是/部分/否
5. TypeScript类型安全性是/部分/否
6. 组件拆分是/部分/否
7. 声明式UI设计是/部分/否
8. 集中式数据管理是/部分/否
9. 常量外部化是/部分/否
10. 避免Props透传是/部分/否

Backend(該当する場合)

后端(适用时)

原則準拠コメント
1. レイヤードアーキテクチャ○/△/×
2. Result型エラーハンドリング○/△/×
3. 入力バリデーション○/△/×
4. 依存性注入○/△/×
5. トランザクション管理○/△/×
6. 認証・認可○/△/×
7. 一貫したAPI設計○/△/×
8. パフォーマンス最適化○/△/×
9. セキュリティバイデザイン○/△/×
10. 可観測性○/△/×
11. 信頼性パターン○/△/×
12. スケーラビリティ○/△/×

原则合规性备注
1. 分层架构与清晰边界是/部分/否
2. 基于Result的错误处理与日志是/部分/否
3. 输入验证与类型安全是/部分/否
4. 依赖注入以提升可测试性是/部分/否
5. 事务管理是/部分/否
6. 认证与授权是/部分/否
7. 统一API设计是/部分/否
8. 性能优化是/部分/否
9. 安全设计是/部分/否
10. 可观测与可调试是/部分/否
11. 可靠性工程是/部分/否
12. 可扩展性与持续优化是/部分/否

レビューコメント

审查意见

良い点

优点

  • [他の開発者が学べる優れた設計・実装のみ記載]
  • [仅记录其他开发者可学习的优秀设计与实现]

改善点・確認点

改进点与待确认点

  • [具体的な改善提案]

  • [具体的改进建议]

変更ファイル一覧

变更文件列表

ファイル変更種別変更内容
path/to/file1.tsModified変更内容の要約
path/to/file2.tsAdded変更内容の要約

文件变更类型变更内容摘要
path/to/file1.ts修改变更内容摘要
path/to/file2.ts新增变更内容摘要

結論

结论

[全体的な評価と、マージ可否の判断材料]

---
[整体评价,以及是否可合并的判断依据]

---

Review Guidelines

审查指南

Important Guidelines for Writing Comments

撰写意见的重要准则

  • Inline Comment Structure:
    • Lead with conclusion: Use a one-line summary of the main point
    • Reasoning and suggestions: After the conclusion, provide detailed explanation
    • Focus on issues: Focus on specific improvements like bug fixes, potential bugs, or readability issues
  • Regarding Positive Feedback:
    • Be selective: Only mention exceptional design choices or innovative implementations
    • Summarize positives: Consolidate overall positive aspects in the summary section
  • 行内评论结构:
    • 先给出结论: 用一句话总结核心观点
    • 理由与建议: 在结论后提供详细解释
    • 聚焦问题: 关注具体的改进点,如bug修复、潜在bug或可读性问题
  • 关于正面反馈:
    • 有所选择: 仅提及出色的设计方案或创新实现
    • 汇总优点: 在概要部分整合整体的积极方面

Review Perspectives

审查维度

[MANDATORY] Implementation Guidelines Compliance
For Frontend Code (
@~/.claude/templates/frontend-implementation-guidelines.md
):
  • Principle 1: Separation of Concerns Through Custom Hooks
  • Principle 2: Comprehensive Error Handling with ErrorScreen components
  • Principle 3: Loading State Management with LoadingScreen components
  • Principle 4: Performance Optimization Through Memoization
  • Principle 5: Type Safety with TypeScript
  • Principle 6: Component Decomposition
  • Principle 7: Declarative UI Design
  • Principle 8: Centralized Data Management
  • Principle 9: Externalization of Constants
  • Principle 10: Avoiding Props Drilling
For Backend Code (
@~/.claude/templates/backend-implementation-guidelines.md
):
  • Principle 1: Layered Architecture with Clear Boundaries
  • Principle 2: Result-Based Error Handling and Logging
  • Principle 3: Input Validation and Type Safety
  • Principle 4: Dependency Injection for Testability
  • Principle 5: Transaction Management
  • Principle 6: Authentication and Authorization
  • Principle 7: Consistent API Design
  • Principle 8: Performance Optimization
  • Principle 9: Security by Design
  • Principle 10: Observable and Debuggable
  • Principle 11: Reliability Engineering
  • Principle 12: Scalability and Continuous Learning
[强制要求] 实现指南合规性
前端代码(
@~/.claude/templates/frontend-implementation-guidelines.md
):
  • 原则1:通过自定义Hook实现关注点分离
  • 原则2:结合ErrorScreen组件的全面错误处理
  • 原则3:结合LoadingScreen组件的加载状态管理
  • 原则4:通过记忆化实现性能优化
  • 原则5:TypeScript类型安全性
  • 原则6:组件拆分
  • 原则7:声明式UI设计
  • 原则8:集中式数据管理
  • 原则9:常量外部化
  • 原则10:避免Props透传
后端代码(
@~/.claude/templates/backend-implementation-guidelines.md
):
  • 原则1:具有清晰边界的分层架构
  • 原则2:基于Result的错误处理与日志
  • 原则3:输入验证与类型安全
  • 原则4:用于提升可测试性的依赖注入
  • 原则5:事务管理
  • 原则6:认证与授权
  • 原则7:统一API设计
  • 原则8:性能优化
  • 原则9:安全设计
  • 原则10:可观测与可调试
  • 原则11:可靠性工程
  • 原则12:可扩展性与持续学习

Evaluation Criteria

评价标准

  • OK: No issues, properly implemented
  • Needs Review: Works correctly but needs confirmation or discussion
  • Problem: Bug, security risk, or design problem
  • 通过:无问题,实现正确
  • 需要审查:功能正常但需确认或讨论
  • 存在问题:bug、安全风险或设计缺陷

Additional Notes

补充说明

  • Provide feedback in Japanese
  • Give specific and actionable feedback
  • Always explicitly state uncertainty - mark speculation clearly
  • Use
    mcp__serena__find_referencing_symbols
    to assess breaking change risks
think super hard
  • 请以中文提供反馈
  • 给出具体且可执行的反馈
  • 若有不确定性需明确说明——清晰标记推测内容
  • 使用
    mcp__serena__find_referencing_symbols
    评估破坏性变更风险
请认真思考