code-reviewer

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Code Reviewer

代码审查工具

A comprehensive code review skill that analyzes pull requests and code changes for quality, security, maintainability, and best practices.
这是一个全面的代码审查技能,可针对质量、安全性、可维护性和最佳实践分析拉取请求(PR)和代码变更。

When This Skill Activates

技能触发场景

This skill activates when you:
  • Ask for a code review
  • Request a PR review
  • Mention reviewing changes
  • Say "review this" or "check this code"
当你进行以下操作时,该技能会触发:
  • 请求进行代码审查
  • 请求PR审查
  • 提及审查代码变更
  • 说“审查这个”或“检查这段代码”

Review Process

审查流程

Phase 1: Context Gathering

阶段1:上下文收集

  1. Get changed files
    bash
    git diff main...HEAD --name-only
    git log main...HEAD --oneline
  2. Get the diff
    bash
    git diff main...HEAD
  3. Understand project context
    • Read relevant documentation
    • Check existing patterns in similar files
    • Identify project-specific conventions
  1. 获取变更文件
    bash
    git diff main...HEAD --name-only
    git log main...HEAD --oneline
  2. 获取差异内容
    bash
    git diff main...HEAD
  3. 理解项目上下文
    • 阅读相关文档
    • 查看相似文件中的现有模式
    • 识别项目特定的约定

Phase 2: Analysis Categories

阶段2:分析类别

1. Correctness

1. 正确性

  • Logic is sound and matches requirements
  • Edge cases are handled
  • Error handling is appropriate
  • No obvious bugs or typos
  • 逻辑合理且符合需求
  • 处理了边界情况
  • 错误处理恰当
  • 无明显bug或拼写错误

2. Security

2. 安全性

  • No hardcoded secrets or credentials
  • Input validation and sanitization
  • SQL injection prevention
  • XSS prevention (for frontend)
  • Authentication/authorization checks
  • Safe handling of user data
  • 无硬编码密钥或凭证
  • 输入验证与清理
  • 防止SQL注入
  • 防止XSS攻击(针对前端)
  • 身份验证/授权检查
  • 用户数据安全处理

3. Performance

3. 性能

  • No N+1 queries
  • Appropriate caching
  • Efficient algorithms
  • No unnecessary computations
  • Memory efficiency
  • 无N+1查询问题
  • 缓存使用恰当
  • 算法高效
  • 无不必要的计算
  • 内存使用高效

4. Code Quality

4. 代码质量

  • Follows DRY principle
  • Follows KISS principle
  • Appropriate abstractions
  • Clear naming conventions
  • Proper typing (if TypeScript)
  • No commented-out code
  • 遵循DRY原则(Don't Repeat Yourself)
  • 遵循KISS原则(Keep It Simple, Stupid)
  • 抽象设计恰当
  • 命名规范清晰
  • 类型定义正确(若使用TypeScript)
  • 无注释掉的代码

5. Testing

5. 测试

  • Tests cover new functionality
  • Tests cover edge cases
  • Test assertions are meaningful
  • No brittle tests
  • 测试覆盖新功能
  • 测试覆盖边界情况
  • 测试断言有意义
  • 无脆弱性测试

6. Documentation

6. 文档

  • Complex logic is explained
  • Public APIs have documentation
  • JSDoc/TSDoc for functions
  • README updated if needed
  • 复杂逻辑有说明
  • 公共API有文档
  • 函数包含JSDoc/TSDoc注释
  • 必要时更新README

7. Maintainability

7. 可维护性

  • Code is readable
  • Consistent style
  • Modular design
  • Separation of concerns
  • 代码可读性强
  • 风格一致
  • 模块化设计
  • 关注点分离

Phase 3: Output Format

阶段3:输出格式

Use this structured format for review feedback:
markdown
undefined
使用以下结构化格式输出审查反馈:
markdown
undefined

Code Review

代码审查结果

Summary

摘要

Brief overview of the changes (2-3 sentences).
变更内容的简要概述(2-3句话)。

Issues by Severity

问题按严重程度分类

Critical

严重

Must fix before merge.
  • Issue Title: Description with file:line reference
合并前必须修复。
  • 问题标题:包含文件:行号的描述

High

高优先级

Should fix before merge unless there's a good reason.
  • Issue Title: Description with file:line reference
除非有合理理由,否则合并前应修复。
  • 问题标题:包含文件:行号的描述

Medium

中等

Consider fixing, can be done in follow-up.
  • Issue Title: Description with file:line reference
考虑修复,可在后续迭代中处理。
  • 问题标题:包含文件:行号的描述

Low

低优先级

Nice to have improvements.
  • Issue Title: Description with file:line reference
可选的优化建议。
  • 问题标题:包含文件:行号的描述

Positive Highlights

亮点

What was done well in this PR.
本次PR中做得好的地方。

Suggestions

建议

Optional improvements that don't require immediate action.
不需要立即处理的可选改进。

Approval Status

审批状态

  • Approved
  • Approved with suggestions
  • Request changes
undefined
  • 已批准
  • 带建议批准
  • 请求变更
undefined

Common Issues to Check

常见检查问题

Security Issues

安全问题

IssuePatternRecommendation
Hardcoded secrets
const API_KEY = "sk-"
Use environment variables
SQL injection
\"SELECT * FROM...\" + user_input
Use parameterized queries
XSS vulnerability
innerHTML = user_input
Sanitize or use textContent
Missing auth checkNew endpoint without
@RequireAuth
Add authentication middleware
问题表现形式建议
硬编码密钥
const API_KEY = "sk-"
使用环境变量
SQL注入
\"SELECT * FROM...\" + user_input
使用参数化查询
XSS漏洞
innerHTML = user_input
清理输入或使用textContent
缺失权限检查新接口未添加
@RequireAuth
添加身份验证中间件

Performance Issues

性能问题

IssuePatternRecommendation
N+1 queryLoop with database callUse eager loading or batch queries
Unnecessary re-renderMissing dependencies in
useEffect
Fix dependency array
Memory leakEvent listener not removedAdd cleanup in useEffect return
Inefficient loopNested loops O(n²)Consider hash map or different algorithm
问题表现形式建议
N+1查询循环中包含数据库调用使用预加载或批量查询
不必要的重渲染
useEffect
依赖缺失
修复依赖数组
内存泄漏事件监听器未移除在useEffect返回函数中添加清理逻辑
低效循环嵌套循环O(n²)考虑使用哈希表或其他算法

Code Quality Issues

代码质量问题

IssuePatternRecommendation
Duplicate codeSimilar blocks repeatedExtract to function
Magic number
if (status === 5)
Use named constant
Long functionFunction >50 linesSplit into smaller functions
Complex condition`a && b
问题表现形式建议
重复代码相似代码块重复出现提取为函数
魔法数字
if (status === 5)
使用命名常量
过长函数函数超过50行拆分为更小的函数
复杂条件`a && b

Testing Issues

测试问题

IssuePatternRecommendation
No testsNew feature without test fileAdd unit tests
Untested edge caseTest only covers happy pathAdd edge case tests
Brittle testTest relies on implementation detailsTest behavior, not implementation
Missing assertionTest doesn't assert anythingAdd proper assertions
问题表现形式建议
无测试新功能无测试文件添加单元测试
未覆盖边界情况仅测试正常流程添加边界情况测试
脆弱性测试测试依赖实现细节测试行为而非实现
缺失断言测试未包含任何断言添加合理的断言

Language-Specific Guidelines

语言特定指南

TypeScript

TypeScript

  • Use
    unknown
    instead of
    any
    for untyped values
  • Prefer
    interface
    for public APIs,
    type
    for unions
  • Use strict mode settings
  • Avoid
    as
    assertions when possible
  • 对于未类型化的值,使用
    unknown
    而非
    any
  • 公共API优先使用
    interface
    ,联合类型优先使用
    type
  • 启用严格模式设置
  • 尽可能避免使用
    as
    断言

React

React

  • Follow Hooks rules
  • Use
    useCallback
    /
    useMemo
    appropriately (not prematurely)
  • Prefer function components
  • Use proper key props in lists
  • Avoid prop drilling with Context
  • 遵循Hooks规则
  • 恰当使用
    useCallback
    /
    useMemo
    (不要过早优化)
  • 优先使用函数组件
  • 列表中使用正确的key属性
  • 使用Context避免属性透传

Python

Python

  • Follow PEP 8 style guide
  • Use type hints
  • Use f-strings for formatting
  • Prefer list comprehensions over map/filter
  • Use context managers for resources
  • 遵循PEP 8风格指南
  • 使用类型提示
  • 使用f-string进行格式化
  • 优先使用列表推导而非map/filter
  • 使用上下文管理器管理资源

Go

Go

  • Handle errors explicitly
  • Use named returns for clarity
  • Keep goroutines simple
  • Use channels for communication
  • Avoid package-level state
  • 显式处理错误
  • 使用命名返回值提升可读性
  • 保持goroutines简洁
  • 使用通道进行通信
  • 避免包级别的状态

Before Approving

批准前确认

Confirm the following:
  • All critical issues are addressed
  • Tests pass locally
  • No merge conflicts
  • Commit messages are clear
  • Documentation is updated
  • Breaking changes are documented
确认以下事项:
  • 所有严重问题已解决
  • 测试在本地通过
  • 无合并冲突
  • 提交信息清晰
  • 文档已更新
  • 破坏性变更已记录

Scripts

脚本

Run the review checklist script:
bash
python scripts/review_checklist.py <pr-number>
运行审查清单脚本:
bash
python scripts/review_checklist.py <pr-number>

References

参考资料

  • references/checklist.md
    - Complete review checklist
  • references/security.md
    - Security review guidelines
  • references/patterns.md
    - Common patterns and anti-patterns
  • references/checklist.md
    - 完整审查清单
  • references/security.md
    - 安全审查指南
  • references/patterns.md
    - 常见模式与反模式