Code Review
Systematic code review that identifies issues in quality, security, performance, and maintainability.
When to Activate
Explicit Triggers
- User says "review this code"
- User says "帮我审查代码"
- User says "code review"
- User says "check my code"
Implicit Triggers
- User asks "is this code good?"
- User completes a feature and asks for feedback
- User mentions concerns about code quality
NOT Activated For
- Simple syntax questions
- Documentation-only changes
- Configuration file edits (unless security-sensitive)
Review Checklist
1. Code Quality
- Readability: Clear variable/function names, appropriate comments
- Complexity: Functions < 50 lines, files < 800 lines, nesting < 4 levels
- DRY Principle: No duplicated logic
- Single Responsibility: Each function/class does one thing
2. Security
- Input Validation: All user inputs validated
- SQL Injection: Parameterized queries used
- XSS Prevention: HTML sanitized
- Secrets: No hardcoded API keys, passwords, tokens
- Authentication: Proper auth/authz checks
3. Error Handling
- Comprehensive: All errors caught and handled
- User-Friendly: Clear error messages for users
- Logging: Detailed error context logged
- No Silent Failures: Never swallow errors
4. Testing
- Coverage: 80%+ test coverage
- Test Quality: Tests are clear, isolated, and meaningful
- Edge Cases: Boundary conditions tested
5. Performance
- Algorithms: Efficient algorithms used (avoid O(n²) when O(n) possible)
- Database: Proper indexes, avoid N+1 queries
- Caching: Appropriate caching for expensive operations
- Resource Cleanup: Connections/files properly closed
Review Process
- Read the code - Understand what it does
- Check against checklist - Systematically review each category
- Prioritize issues - CRITICAL > HIGH > MEDIUM > LOW
- Provide examples - Show how to fix issues
- Suggest improvements - Offer better alternatives
Issue Severity Levels
- CRITICAL: Security vulnerabilities, data loss risks
- HIGH: Bugs, major performance issues, broken functionality
- MEDIUM: Code quality issues, minor performance problems
- LOW: Style inconsistencies, minor improvements
Example Review Output
## Code Review Results
### CRITICAL Issues (0)
None found.
### HIGH Issues (1)
1. **SQL Injection Risk** (line 45)
- Current: `query = "SELECT * FROM users WHERE id = " + userId`
- Fix: Use parameterized query: `query("SELECT * FROM users WHERE id = ?", [userId])`
### MEDIUM Issues (2)
1. **Function Too Long** (line 100-180)
- `processUserData()` is 80 lines, should be < 50
- Suggest: Extract validation, transformation, and saving into separate functions
2. **Missing Error Handling** (line 200)
- `await fetchData()` not wrapped in try-catch
- Add error handling to prevent unhandled promise rejection
### LOW Issues (1)
1. **Variable Naming** (line 30)
- `d` is unclear, rename to `userData` or `userDetails`
Best Practices
- Be Constructive: Focus on improvement, not criticism
- Explain Why: Don't just point out issues, explain the reasoning
- Provide Examples: Show concrete fixes, not just descriptions
- Prioritize: Focus on critical/high issues first
- Be Specific: Reference exact line numbers and code snippets
Related Resources
- Security guidelines: Check for OWASP Top 10 vulnerabilities
- Testing standards: Ensure 80%+ coverage
- Code style: Follow language-specific conventions
1---2name: code-review3description: Comprehensive code review focusing on quality, security, and best practices4---56# Code Review78Systematic code review that identifies issues in quality, security, performance, and maintainability.910## When to Activate1112### Explicit Triggers13- User says "review this code"14- User says "帮我审查代码"15- User says "code review"16- User says "check my code"1718### Implicit Triggers19- User asks "is this code good?"20- User completes a feature and asks for feedback21- User mentions concerns about code quality2223### NOT Activated For24- Simple syntax questions25- Documentation-only changes26- Configuration file edits (unless security-sensitive)2728## Review Checklist2930### 1. Code Quality31- **Readability**: Clear variable/function names, appropriate comments32- **Complexity**: Functions < 50 lines, files < 800 lines, nesting < 4 levels33- **DRY Principle**: No duplicated logic34- **Single Responsibility**: Each function/class does one thing3536### 2. Security37- **Input Validation**: All user inputs validated38- **SQL Injection**: Parameterized queries used39- **XSS Prevention**: HTML sanitized40- **Secrets**: No hardcoded API keys, passwords, tokens41- **Authentication**: Proper auth/authz checks4243### 3. Error Handling44- **Comprehensive**: All errors caught and handled45- **User-Friendly**: Clear error messages for users46- **Logging**: Detailed error context logged47- **No Silent Failures**: Never swallow errors4849### 4. Testing50- **Coverage**: 80%+ test coverage51- **Test Quality**: Tests are clear, isolated, and meaningful52- **Edge Cases**: Boundary conditions tested5354### 5. Performance55- **Algorithms**: Efficient algorithms used (avoid O(n²) when O(n) possible)56- **Database**: Proper indexes, avoid N+1 queries57- **Caching**: Appropriate caching for expensive operations58- **Resource Cleanup**: Connections/files properly closed5960## Review Process61621. **Read the code** - Understand what it does632. **Check against checklist** - Systematically review each category643. **Prioritize issues** - CRITICAL > HIGH > MEDIUM > LOW654. **Provide examples** - Show how to fix issues665. **Suggest improvements** - Offer better alternatives6768## Issue Severity Levels6970- **CRITICAL**: Security vulnerabilities, data loss risks71- **HIGH**: Bugs, major performance issues, broken functionality72- **MEDIUM**: Code quality issues, minor performance problems73- **LOW**: Style inconsistencies, minor improvements7475## Example Review Output7677```markdown78## Code Review Results7980### CRITICAL Issues (0)81None found.8283### HIGH Issues (1)841. **SQL Injection Risk** (line 45)85 - Current: `query = "SELECT * FROM users WHERE id = " + userId`86 - Fix: Use parameterized query: `query("SELECT * FROM users WHERE id = ?", [userId])`8788### MEDIUM Issues (2)891. **Function Too Long** (line 100-180)90 - `processUserData()` is 80 lines, should be < 5091 - Suggest: Extract validation, transformation, and saving into separate functions92932. **Missing Error Handling** (line 200)94 - `await fetchData()` not wrapped in try-catch95 - Add error handling to prevent unhandled promise rejection9697### LOW Issues (1)981. **Variable Naming** (line 30)99 - `d` is unclear, rename to `userData` or `userDetails`100```101102## Best Practices103104- **Be Constructive**: Focus on improvement, not criticism105- **Explain Why**: Don't just point out issues, explain the reasoning106- **Provide Examples**: Show concrete fixes, not just descriptions107- **Prioritize**: Focus on critical/high issues first108- **Be Specific**: Reference exact line numbers and code snippets109110## Related Resources111112- Security guidelines: Check for OWASP Top 10 vulnerabilities113- Testing standards: Ensure 80%+ coverage114- Code style: Follow language-specific conventions