| name | code-review |
| description | Perform thorough code reviews with focus on security, performance, maintainability, and best practices. Use when reviewing code changes, pull requests, entire files, or codebase audits across any programming language. |
Code Review Skill
Overview
This skill provides a structured approach to code reviews, covering security vulnerabilities, performance issues, code quality, maintainability, and best practices across multiple programming languages.
Review Approach Decision Tree
Choose review depth based on request:
- Quick review / sanity check ā Use Quick Review Checklist (5-10 items)
- Standard PR review ā Use Standard Review (security, performance, maintainability)
- Comprehensive audit ā Use Deep Review (all categories + architecture)
- Specific focus (e.g., "check security") ā Use relevant focused section
Default to Standard Review unless otherwise specified.
Review Structure
Organize findings by severity and category:
Severity Levels
š“ Critical - Must fix before merge
- Security vulnerabilities
- Data loss risks
- Breaking changes
- Critical bugs
š” Important - Should fix soon
- Performance issues
- Poor error handling
- Maintainability concerns
- API design problems
šµ Minor - Nice to have
- Style inconsistencies
- Documentation gaps
- Minor optimizations
- Suggestion for refactoring
ā Positive - What's done well
- Good patterns used
- Clever solutions
- Solid error handling
- Well-structured code
Standard Review Checklist
1. Security
Authentication & Authorization
- Are authentication checks present and correct?
- Is authorization enforced at the right level?
- Are user permissions validated before sensitive operations?
Input Validation
- Is all user input validated and sanitized?
- Are there SQL injection risks? (Check raw queries, string concatenation)
- Are there XSS vulnerabilities? (Check unescaped output)
- Are file uploads validated properly? (Type, size, content)
Sensitive Data
- Are secrets/API keys hardcoded? (Should use environment variables)
- Is sensitive data logged inappropriately?
- Are passwords hashed properly? (bcrypt, argon2, not MD5/SHA1)
- Is PII (Personally Identifiable Information) handled correctly?
Common Vulnerabilities
- Path traversal:
../../../etc/passwd - Command injection: Unescaped shell commands
- Deserialization: Unsafe pickle/eval/JSON parsing
- CSRF: Missing CSRF tokens on state-changing operations
- Timing attacks: Non-constant-time comparisons for secrets
2. Performance
Algorithmic Complexity
- Are there O(n²) or worse algorithms where O(n log n) or O(n) would work?
- Nested loops over large datasets?
- Inefficient string concatenation in loops?
Database Queries
- N+1 query problems? (Load related data in single query)
- Missing indexes on frequently queried columns?
- SELECT * when only specific columns needed?
- Queries inside loops?
Resource Management
- Are files/connections/streams properly closed?
- Memory leaks? (Event listeners not cleaned up, circular references)
- Large objects kept in memory unnecessarily?
Caching Opportunities
- Repeated expensive computations that could be cached?
- API calls that could be batched or memoized?
- Static data fetched on every request?
3. Error Handling
Exception Handling
- Are exceptions caught at the right level?
- Are errors logged with sufficient context?
- Are generic catch-all blocks hiding specific errors?
- Are custom errors informative?
Edge Cases
- Null/undefined checks where needed?
- Empty array/collection handling?
- Division by zero checks?
- Boundary conditions tested?
User-Facing Errors
- Are error messages helpful but not exposing internals?
- Are errors returned with appropriate HTTP status codes?
- Is there graceful degradation when services fail?
4. Code Quality
Readability
- Are variable/function names clear and descriptive?
- Is the code self-documenting or does it need comments?
- Are functions doing one thing (Single Responsibility)?
- Is nesting depth reasonable (< 4 levels)?
Maintainability
- Are magic numbers/strings extracted to named constants?
- Is there duplicated code that should be DRYed?
- Are functions too long (>50 lines is a smell)?
- Is coupling loose and cohesion high?
Testing
- Are there tests for the new/changed code?
- Are edge cases covered?
- Are tests meaningful or just achieving coverage?
- Are integration points tested?
5. Best Practices (Language-Specific)
JavaScript/TypeScript
- Using const/let instead of var?
- Avoiding == in favor of ===?
- Proper async/await usage (not missing await)?
- TypeScript types comprehensive and not using
anyexcessively?
Python
- Following PEP 8 style guidelines?
- Using context managers (with statement) for resources?
- Proper use of list comprehensions vs loops?
- Type hints for function signatures?
Go
- Errors checked and not ignored?
- Defer used for cleanup?
- Interfaces kept small?
- Goroutines have proper lifecycle management?
Java
- Resources in try-with-resources?
- Using appropriate collection types?
- Avoiding primitive obsession?
- Proper exception hierarchy?
Rust
- Proper error propagation with
?operator? - Ownership and borrowing used correctly?
- No unnecessary clones?
- Unsafe blocks justified and minimal?
Web Graphics (Canvas/WebGL/WebGPU)
- Draw calls batched and minimized?
- Texture atlases used instead of individual textures?
- Shaders optimized (precision, conditionals, uniform updates)?
- Resources properly disposed (textures, buffers)?
- Heavy computation offloaded to workers or WASM?
- Object pooling for frequently created objects?
- See
references/web-graphics-performance.mdfor detailed patterns
Deep Review (Comprehensive Audit)
Include everything from Standard Review plus:
Architecture & Design
Design Patterns
- Are appropriate design patterns used?
- Are patterns over-engineered for the problem?
- Is there clear separation of concerns?
Dependencies
- Are dependencies up-to-date and secure?
- Are heavy dependencies justified?
- Is the dependency graph reasonable?
API Design
- Are API contracts clear and versioned?
- Is the API consistent with existing patterns?
- Are breaking changes properly communicated?
Code Organization
Project Structure
- Are files organized logically?
- Is code grouped by feature or layer appropriately?
- Are module boundaries clear?
Configuration
- Is configuration externalized?
- Are environment-specific configs handled properly?
- Are defaults sensible?
Documentation
Code Documentation
- Are complex algorithms explained?
- Are public APIs documented?
- Are assumptions stated?
README & Guides
- Is setup documentation current?
- Are examples provided?
- Are breaking changes noted?
Quick Review Checklist
For rapid feedback (use when time is limited):
- Security: Any obvious vulnerabilities?
- Correctness: Does the logic look sound?
- Edge cases: Null checks, empty arrays, boundary conditions?
- Performance: Any obvious inefficiencies?
- Error handling: Are errors caught and handled?
- Readability: Is the code easy to understand?
- Tests: Are there tests for this change?
- Breaking changes: Any API changes that need communication?
Review Output Format
Structure reviews clearly:
## Review Summary
[1-2 sentence overview of the changes and overall assessment]
## Critical Issues š“
- [Issue with specific line reference and fix suggestion]
## Important Issues š”
- [Issue with context and recommendation]
## Minor Issues šµ
- [Suggestion for improvement]
## Positive Feedback ā
- [What's done well]
## Recommendations
[Overall suggestions or next steps]
Review Tips
Be Constructive
- Frame feedback as questions when uncertain: "Could this cause X if Y happens?"
- Suggest solutions, not just problems
- Acknowledge good code: "Nice use of X pattern here"
- Explain the "why" behind suggestions
Prioritize
- Focus on high-impact issues first
- Don't nitpick style in critical reviews
- Separate must-fix from nice-to-have
- Consider the scope of changes (minor fix vs major feature)
Context Matters
- Consider the codebase's existing patterns
- Understand the urgency (hotfix vs planned feature)
- Recognize team conventions may differ from ideal
- Ask clarifying questions if intent is unclear
Code Review Anti-Patterns to Avoid
- Bikeshedding: Endless debate over trivial matters
- Style crusading: Enforcing personal preferences
- Perfectionism: Blocking reasonable code for minor issues
- Scope creep: Requesting unrelated changes
- Rubber stamping: Approving without actually reviewing
Language-Specific Guidance
For detailed language-specific patterns, see references/ directory for:
- JavaScript/TypeScript best practices
- Python idioms and patterns
- Security vulnerability patterns by language
- Web graphics performance (Canvas, WebGL, WebGPU, WebAssembly) - Use for web app graphics/game performance
Common Vulnerability Patterns
SQL Injection
# ā Vulnerable
query = f"SELECT * FROM users WHERE id = {user_id}"
# ā
Safe
query = "SELECT * FROM users WHERE id = ?"
cursor.execute(query, (user_id,))
XSS (Cross-Site Scripting)
// ā Vulnerable
element.innerHTML = userInput;
// ā
Safe
element.textContent = userInput;
// Or use a sanitization library
Path Traversal
# ā Vulnerable
with open(f"/uploads/{filename}") as f:
content = f.read()
# ā
Safe
from pathlib import Path
safe_path = Path("/uploads").resolve() / filename
if not safe_path.resolve().is_relative_to(Path("/uploads").resolve()):
raise ValueError("Invalid path")
Command Injection
// ā Vulnerable
exec(`ffmpeg -i ${userFile} output.mp4`);
// ā
Safe
execFile('ffmpeg', ['-i', userFile, 'output.mp4']);
Review Workflow
- Understand the context: What problem is being solved?
- Review high-level approach: Is the solution appropriate?
- Check security first: Any vulnerabilities?
- Review correctness: Does the logic work?
- Check performance: Any efficiency issues?
- Assess maintainability: Is it readable and maintainable?
- Verify tests: Are changes tested?
- Provide summary: Categorized feedback with severity