AgentSkillsCN

code-review

在审查代码的质量、可维护性和测试覆盖率时使用。它会分析实现和测试,以识别代码异味、架构问题以及覆盖率缺口。

SKILL.md
--- frontmatter
name: code-review
description: Use when reviewing code for quality, maintainability, and test coverage. Analyzes implementation and tests to identify code smells, architectural issues, and coverage gaps.

Code Review

Overview

Systematic code review covering implementation quality, architectural alignment, and test coverage. Review both the code AND its tests together.

When to Use

  • After writing a new function or module
  • Before merging significant changes
  • When refactoring existing code
  • When asked to "review", "check", or "look over" code

Review Process

1. Gather Context

StepAction
Identify filesUse Glob to find implementation + test files
Read implementationFocus on the changed/new code
Read testsFind co-located *.test.ts, *.spec.ts, or __tests__/ files
Check project patternsLook at similar files for conventions

2. Analyze Implementation

Check each category, note specific issues with file:line references:

CategoryWhat to Check
CorrectnessLogic errors, edge cases, error handling
ClarityNaming, comments, complexity
MaintainabilityDRY, single responsibility, coupling
ArchitectureFollows project patterns, proper abstractions
SecurityInput validation, injection risks, sensitive data

3. Analyze Tests

CategoryWhat to Check
CoverageHappy paths, edge cases, error conditions
AssertionsTests assert meaningful behavior, not just that code runs
IsolationTests are independent, no shared mutable state
IntegrationCross-component behavior is tested
NamingTest names clearly describe what they're testing

4. Output Format

markdown
## Summary
[One paragraph overview and overall assessment]

## Issues Found

### Critical (Must Fix)
- [file:line] Issue description and fix

### Concerns (Should Address)  
- [file:line] Significant issues that aren't blocking

### Suggestions (Consider)
- [file:line] Minor improvements or alternatives

## Test Coverage Analysis
[Assessment of test quality and coverage gaps]

## Verdict: [APPROVED / NEEDS REVISION / REJECTED]
[Justification for verdict]

Code Smells

SmellSigns
God class/functionToo many responsibilities
Long parameter list>3-4 params, use options object
Deep nesting>3 levels, use early returns
Magic valuesHardcoded strings/numbers without explanation
Copy-paste codeDuplicate blocks, extract utility
Silent error swallowingEmpty catch blocks, unhandled promise rejections, missing error propagation
Async context issuesSync blocking in async code, unhandled async callbacks, missing try-catch in async handlers
Mutable state misuseMutable where immutable would be cleaner
Tight couplingUnrelated components depending on each other
TODO/FIXME/HACKLeft without justification or tracking

Architectural Concerns

ConcernWhat to Look For
Single responsibilityOne class/function doing too many things
Error boundariesMissing error handling at component boundaries
Leaky abstractionsImplementation details exposed
State managementPatterns that won't scale
Async patternsBlocking in async contexts, callback error handling
TestabilityPatterns that make testing difficult
Hard-coded configValues that should be configurable

Verdict Criteria

APPROVED when:

  • No critical issues present
  • Test coverage sufficient for complexity
  • Hacky code has clear justification
  • Architecture supports maintainability

NEEDS REVISION when:

  • Significant concerns but approach is sound
  • Test coverage has gaps but tests exist
  • Issues fixable without major restructuring

REJECTED when:

  • Fundamental architectural problems
  • Critical bugs or security issues
  • No meaningful tests for complex logic
  • Code is unmaintainable

Review Guidelines

  • Be specific: Reference exact line numbers and code snippets
  • Be constructive: Explain WHY something is problematic, suggest alternatives
  • Acknowledge good patterns: Note well-designed aspects
  • Consider context: Prototype vs production have different standards
  • Respect conventions: Check CLAUDE.md or project guidelines
  • Don't nitpick: Focus on issues that matter for maintainability
  • Ask for clarification: If intent is unclear, ask rather than assume wrong