Reviews code for best practices, bugs, and improvements. Invoke when user asks for code review, before merging changes, or when implementing new features.
This skill provides comprehensive code review guidance to ensure code quality, maintainability, and best practices.
Invoke this skill when the user:
// Good: Use const/let instead of var
const API_URL = 'https://api.example.com';
// Good: Use arrow functions for callbacks
const processData = (data) => {
return data.map(item => item.value);
};
// Good: Use async/await for async operations
async function fetchData() {
try {
const response = await fetch(API_URL);
return await response.json();
} catch (error) {
console.error('Error fetching data:', error);
throw error;
}
}
// Good: Use template literals
const message = `Hello ${name}, you have ${count} messages`;
// Good: Destructure objects
const { id, name, email } = user;
# Good: Use descriptive variable names
user_authentication_token = get_auth_token()
# Good: Use list comprehensions
squared_numbers = [x**2 for x in range(10)]
# Good: Use context managers
with open('file.txt', 'r') as f:
content = f.read()
# Good: Use type hints
def calculate_total(price: float, quantity: int) -> float:
return price * quantity
# Good: Use f-strings
message = f"Hello {name}, you have {count} messages"
// Good: Use functional components with hooks
function UserProfile({ userId }) {
const [user, setUser] = useState(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
fetchUser(userId).then(data => {
setUser(data);
setLoading(false);
});
}, [userId]);
if (loading) return <Spinner />;
return <div>{user.name}</div>;
}
// Good: Use React.memo for expensive components
const ExpensiveComponent = React.memo(function ExpensiveComponent({ data }) {
return <div>{/* expensive rendering */}</div>;
});
// Good: Use useCallback for event handlers
const handleClick = useCallback(() => {
doSomething(id);
}, [id]);
## Issue: [Brief description]
**Location**: [file:line]
**Severity**: [Critical/Major/Minor]
**Type**: [Bug/Performance/Security/Style]
**Problem**: [Detailed explanation of the issue]
**Impact**: [Why this matters]
**Suggestion**: [How to fix it]
**Example**:
```code
// Before
[problematic code]
// After
[improved code]
## Code Review Best Practices
### For Reviewers
- Review code promptly
- Focus on the most important issues first
- Be respectful and constructive
- Ask questions rather than making demands
- Recognize good work
- Learn from the code you review
### For Authors
- Keep PRs small and focused
- Write clear commit messages
- Include tests
- Respond to feedback promptly
- Be open to suggestions
- Learn from feedback
## Automated Tools
### Linting
- ESLint (JavaScript/TypeScript)
- Pylint (Python)
- RuboCop (Ruby)
- GoLint (Go)
### Static Analysis
- SonarQube
- CodeQL
- DeepSource
- Codacy
### Security Scanning
- Snyk
- Dependabot
- OWASP Dependency-Check
- Bandit (Python)
### Code Quality Metrics
- CodeClimate
- Codacy
- Coverity
- LGTM
## Common Patterns
### Error Handling
```javascript
// Good: Proper error handling
async function fetchData() {
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
} catch (error) {
console.error('Fetch error:', error);
throw error;
}
}
// Good: Input validation
function processUserInput(input) {
if (!input || typeof input !== 'string') {
throw new Error('Invalid input');
}
const sanitized = input.trim();
if (sanitized.length === 0) {
throw new Error('Input cannot be empty');
}
return sanitized;
}
// Good: Proper async handling
async function processItems(items) {
const results = [];
for (const item of items) {
try {
const result = await processItem(item);
results.push(result);
} catch (error) {
console.error(`Error processing ${item}:`, error);
results.push(null);
}
}
return results;
}
Remember: Code review is not just about finding bugs—it's about improving code quality, sharing knowledge, and building better software together. Be constructive, be specific, and always aim to help the author improve.