code-reviewer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCode 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:上下文收集
-
Get changed filesbash
git diff main...HEAD --name-only git log main...HEAD --oneline -
Get the diffbash
git diff main...HEAD -
Understand project context
- Read relevant documentation
- Check existing patterns in similar files
- Identify project-specific conventions
-
获取变更文件bash
git diff main...HEAD --name-only git log main...HEAD --oneline -
获取差异内容bash
git diff main...HEAD -
理解项目上下文
- 阅读相关文档
- 查看相似文件中的现有模式
- 识别项目特定的约定
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
undefinedCode 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- 已批准
- 带建议批准
- 请求变更
undefinedCommon Issues to Check
常见检查问题
Security Issues
安全问题
| Issue | Pattern | Recommendation |
|---|---|---|
| Hardcoded secrets | | Use environment variables |
| SQL injection | | Use parameterized queries |
| XSS vulnerability | | Sanitize or use textContent |
| Missing auth check | New endpoint without | Add authentication middleware |
| 问题 | 表现形式 | 建议 |
|---|---|---|
| 硬编码密钥 | | 使用环境变量 |
| SQL注入 | | 使用参数化查询 |
| XSS漏洞 | | 清理输入或使用textContent |
| 缺失权限检查 | 新接口未添加 | 添加身份验证中间件 |
Performance Issues
性能问题
| Issue | Pattern | Recommendation |
|---|---|---|
| N+1 query | Loop with database call | Use eager loading or batch queries |
| Unnecessary re-render | Missing dependencies in | Fix dependency array |
| Memory leak | Event listener not removed | Add cleanup in useEffect return |
| Inefficient loop | Nested loops O(n²) | Consider hash map or different algorithm |
| 问题 | 表现形式 | 建议 |
|---|---|---|
| N+1查询 | 循环中包含数据库调用 | 使用预加载或批量查询 |
| 不必要的重渲染 | | 修复依赖数组 |
| 内存泄漏 | 事件监听器未移除 | 在useEffect返回函数中添加清理逻辑 |
| 低效循环 | 嵌套循环O(n²) | 考虑使用哈希表或其他算法 |
Code Quality Issues
代码质量问题
| Issue | Pattern | Recommendation |
|---|---|---|
| Duplicate code | Similar blocks repeated | Extract to function |
| Magic number | | Use named constant |
| Long function | Function >50 lines | Split into smaller functions |
| Complex condition | `a && b |
| 问题 | 表现形式 | 建议 |
|---|---|---|
| 重复代码 | 相似代码块重复出现 | 提取为函数 |
| 魔法数字 | | 使用命名常量 |
| 过长函数 | 函数超过50行 | 拆分为更小的函数 |
| 复杂条件 | `a && b |
Testing Issues
测试问题
| Issue | Pattern | Recommendation |
|---|---|---|
| No tests | New feature without test file | Add unit tests |
| Untested edge case | Test only covers happy path | Add edge case tests |
| Brittle test | Test relies on implementation details | Test behavior, not implementation |
| Missing assertion | Test doesn't assert anything | Add proper assertions |
| 问题 | 表现形式 | 建议 |
|---|---|---|
| 无测试 | 新功能无测试文件 | 添加单元测试 |
| 未覆盖边界情况 | 仅测试正常流程 | 添加边界情况测试 |
| 脆弱性测试 | 测试依赖实现细节 | 测试行为而非实现 |
| 缺失断言 | 测试未包含任何断言 | 添加合理的断言 |
Language-Specific Guidelines
语言特定指南
TypeScript
TypeScript
- Use instead of
unknownfor untyped valuesany - Prefer for public APIs,
interfacefor unionstype - Use strict mode settings
- Avoid assertions when possible
as
- 对于未类型化的值,使用而非
unknownany - 公共API优先使用,联合类型优先使用
interfacetype - 启用严格模式设置
- 尽可能避免使用断言
as
React
React
- Follow Hooks rules
- Use /
useCallbackappropriately (not prematurely)useMemo - 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
参考资料
- - Complete review checklist
references/checklist.md - - Security review guidelines
references/security.md - - Common patterns and anti-patterns
references/patterns.md
- - 完整审查清单
references/checklist.md - - 安全审查指南
references/security.md - - 常见模式与反模式
references/patterns.md