Use when reviewing code, conducting code reviews, analyzing pull requests, or when the user mentions "code review", "PR review", "code quality", or "static analysis".
How this skill is triggered — by the user, by Claude, or both
Slash command
/agent-skills-collection:code-reviewerThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Code Reviewer provides a systematic approach to conducting thorough code reviews. It helps identify code quality issues, potential bugs, security vulnerabilities, performance problems, and ensures adherence to best practices and coding standards before merging changes.
Code Reviewer provides a systematic approach to conducting thorough code reviews. It helps identify code quality issues, potential bugs, security vulnerabilities, performance problems, and ensures adherence to best practices and coding standards before merging changes.
Use this skill when:
Before diving into details, understand the scope and purpose:
Read the PR description
Identify the scope
Check the baseline
Check for security vulnerabilities first:
// ❌ BAD: Unvalidated input
function queryDatabase(userInput) {
return db.query(`SELECT * FROM users WHERE id = ${userInput}`);
}
// ✅ GOOD: Parameterized query
function queryDatabase(userId) {
return db.query("SELECT * FROM users WHERE id = ?", [userId]);
}
| Issue | What to Check | Fix |
|---|---|---|
| SQL Injection | String concatenation in queries | Use parameterized queries |
| XSS | Unescaped user input in HTML | Sanitize and escape output |
| CSRF | Missing CSRF tokens on forms | Add anti-CSRF tokens |
| SSRF | User-provided URLs fetched server-side | Validate and sanitize URLs |
| IDOR | Direct object references without auth check | Verify authorization |
| Path Traversal | File paths constructed from user input | Validate and sanitize paths |
# ❌ BAD: God function doing multiple things
def process_user(user_data):
validate(user_data)
save_to_db(user_data)
send_email(user_data)
update_analytics(user_data)
log_action(user_data)
# ✅ GOOD: Separated concerns
def process_user(user_data):
validate(user_data)
save_to_db(user_data)
notify_user(user_data)
track_action(user_data)
// ❌ BAD: Swallowed error
try {
doSomething();
} catch (e) {
// Silently ignored
}
// ✅ GOOD: Proper error handling
try {
doSomething();
} catch (error) {
logger.error("Failed to do something", { error });
throw new AppError("Operation failed", error);
}
// ❌ BAD: Any type
function processData(data: any) {
return data.value;
}
// ✅ GOOD: Proper typing
function processData(data: UserData): ProcessedResult {
return data.value;
}
| Type | Convention | Example |
|---|---|---|
| Variables | camelCase | userName, isActive |
| Constants | UPPER_SNAKE_CASE | MAX_RETRY_COUNT |
| Functions | camelCase (verb phrase) | getUserById, calculateTotal |
| Classes | PascalCase (noun) | UserService, PaymentProcessor |
| Interfaces | PascalCase (noun phrase) | UserRepository, IUserService |
# ❌ BAD: O(n²) nested loop
for user in users:
for order in orders:
if order.user_id == user.id:
process(user, order)
# ✅ GOOD: O(n) with lookup
orders_by_user = defaultdict(list)
for order in orders:
orders_by_user[order.user_id].append(order)
for user in users:
for order in orders_by_user[user.id]:
process(user, order)
-- ❌ BAD: N+1 queries
SELECT * FROM users;
-- Then for each user:
SELECT * FROM orders WHERE user_id = ?;
-- ✅ GOOD: Single joined query
SELECT u.*, o.* FROM users u
LEFT JOIN orders o ON u.id = o.user_id;
// ❌ BAD: No tests for edge cases
function divide(a, b) {
return a / b;
}
// ✅ GOOD: Edge cases covered
function divide(a, b) {
if (b === 0) {
throw new Error("Division by zero");
}
return a / b;
}
# ❌ BAD: Poor test structure
def test_user():
user = create_user()
assert user.name == "John" # What did we create?
user.name = "Jane"
save(user)
assert user.name == "Jane" # Saved what?
# ✅ GOOD: Clear AAA pattern
def test_create_user():
# Arrange
user_data = {'name': 'John', 'email': '[email protected]'}
# Act
user = create_user(user_data)
# Assert
assert user.name == 'John'
assert user.email == '[email protected]'
assert user.id is not None
# ❌ BAD: No documentation
def calculate(x, y):
return (x + y) / 2
# ✅ GOOD: Comprehensive docstring
def calculate(x, y):
"""Calculate the arithmetic mean of two numbers.
Args:
x: First number (int or float)
y: Second number (int or float)
Returns:
The arithmetic mean of x and y.
Raises:
TypeError: If x or y are not numeric types.
Examples:
>>> calculate(2, 4)
3.0
>>> calculate(-1, 1)
0.0
"""
if not isinstance(x, (int, float)) or not isinstance(y, (int, float)):
raise TypeError('Both arguments must be numeric')
return (x + y) / 2
## Issue: [Brief title]
**Problem:** [What's wrong]
**Impact:** [Why it matters]
**Suggestion:** [How to fix]
**Example:** [Code snippet if applicable]
| Comment | Meaning |
|---|---|
| "Can we extract this into a helper?" | Code duplication |
| "Consider adding tests for this edge case" | Missing test coverage |
| "This might cause issues if x is null" | Potential bug |
| "Have you considered using y instead?" | Better approach available |
| "Nit: variable name could be clearer" | Minor style issue |
| "This is outside the scope of this PR" | Keep changes focused |
| Review Phase | Focus Areas |
|---|---|
| Security | Input validation, SQL injection, XSS, auth |
| Quality | Structure, naming, error handling, types |
| Performance | Algorithms, queries, caching, memory |
| Testing | Coverage, edge cases, test quality |
| Documentation | API docs, comments, changelog |
A thorough code review catches issues before they reach production. Focus on security first, then code quality, performance, testing, and documentation. Always be constructive and help the author improve, not just criticize.
Guides creation, editing, and verification of skills for AI coding agents using test-driven development with subagent scenarios. Use when authoring or debugging skills.
npx claudepluginhub ntk148v/skills --plugin development-skills