1
---
2
name: code-review-excellence
3
description: Master effective code review practices to provide constructive feedback, catch bugs early, and foster knowledge sharing while maintaining team morale. Use when reviewing pull requests, establishing review standards, or mentoring developers.
4
---
5
6
# Code Review Excellence
7
8
Transform code reviews from gatekeeping to knowledge sharing through constructive feedback, systematic analysis, and collaborative improvement.
9
10
## When to Use This Skill
11
12
- Reviewing pull requests and code changes
13
- Establishing code review standards for teams
14
- Mentoring junior developers through reviews
15
- Conducting architecture reviews
16
- Creating review checklists and guidelines
17
- Improving team collaboration
18
- Reducing code review cycle time
19
- Maintaining code quality standards
20
21
## Core Principles
22
23
### 1. The Review Mindset
24
25
**Goals of Code Review:**
26
27
- Catch bugs and edge cases
28
- Ensure code maintainability
29
- Share knowledge across team
30
- Enforce coding standards
31
- Improve design and architecture
32
- Build team culture
33
34
**Not the Goals:**
35
36
- Show off knowledge
37
- Nitpick formatting (use linters)
38
- Block progress unnecessarily
39
- Rewrite to your preference
40
41
### 2. Effective Feedback
42
43
**Good Feedback is:**
44
45
- Specific and actionable
46
- Educational, not judgmental
47
- Focused on the code, not the person
48
- Balanced (praise good work too)
49
- Prioritized (critical vs nice-to-have)
50
51
```markdown
52
❌ Bad: "This is wrong."
53
✅ Good: "This could cause a race condition when multiple users
54
access simultaneously. Consider using a mutex here."
55
56
❌ Bad: "Why didn't you use X pattern?"
57
✅ Good: "Have you considered the Repository pattern? It would
58
make this easier to test. Here's an example: [link]"
59
60
❌ Bad: "Rename this variable."
61
✅ Good: "[nit] Consider `userCount` instead of `uc` for
62
clarity. Not blocking if you prefer to keep it."
63
```
64
65
### 3. Review Scope
66
67
**What to Review:**
68
69
- Logic correctness and edge cases
70
- Security vulnerabilities
71
- Performance implications
72
- Test coverage and quality
73
- Error handling
74
- Documentation and comments
75
- API design and naming
76
- Architectural fit
77
78
**What Not to Review Manually:**
79
80
- Code formatting (use Prettier, Black, etc.)
81
- Import organization
82
- Linting violations
83
- Simple typos
84
85
## Review Process
86
87
### Phase 1: Context Gathering (2-3 minutes)
88
89
```markdown
90
Before diving into code, understand:
91
92
1. Read PR description and linked issue
93
2. Check PR size (>400 lines? Ask to split)
94
3. Review CI/CD status (tests passing?)
95
4. Understand the business requirement
96
5. Note any relevant architectural decisions
97
```
98
99
### Phase 2: High-Level Review (5-10 minutes)
100
101
```markdown
102
1. **Architecture & Design**
103
- Does the solution fit the problem?
104
- Are there simpler approaches?
105
- Is it consistent with existing patterns?
106
- Will it scale?
107
108
2. **File Organization**
109
- Are new files in the right places?
110
- Is code grouped logically?
111
- Are there duplicate files?
112
113
3. **Testing Strategy**
114
- Are there tests?
115
- Do tests cover edge cases?
116
- Are tests readable?
117
```
118
119
### Phase 3: Line-by-Line Review (10-20 minutes)
120
121
```markdown
122
For each file:
123
124
1. **Logic & Correctness**
125
- Edge cases handled?
126
- Off-by-one errors?
127
- Null/undefined checks?
128
- Race conditions?
129
130
2. **Security**
131
- Input validation?
132
- SQL injection risks?
133
- XSS vulnerabilities?
134
- Sensitive data exposure?
135
136
3. **Performance**
137
- N+1 queries?
138
- Unnecessary loops?
139
- Memory leaks?
140
- Blocking operations?
141
142
4. **Maintainability**
143
- Clear variable names?
144
- Functions doing one thing?
145
- Complex code commented?
146
- Magic numbers extracted?
147
```
148
149
### Phase 4: Summary & Decision (2-3 minutes)
150
151
```markdown
152
1. Summarize key concerns
153
2. Highlight what you liked
154
3. Make clear decision:
155
- ✅ Approve
156
- 💬 Comment (minor suggestions)
157
- 🔄 Request Changes (must address)
158
4. Offer to pair if complex
159
```
160
161
Before writing review feedback, read `references/review-techniques.md` for checklists, question framing, collaboration, and severity techniques.
162
163
Before language-specific, architectural, test-quality, or security review, read `references/review-patterns.md` for review patterns and checklists.
164
165
## Giving Difficult Feedback
166
167
### Pattern: The Sandwich Method (Modified)
168
169
```markdown
170
Traditional: Praise + Criticism + Praise (feels fake)
171
172
Better: Context + Specific Issue + Helpful Solution
173
174
Example:
175
"I noticed the payment processing logic is inline in the
176
controller. This makes it harder to test and reuse.
177
178
[Specific Issue]
179
The calculateTotal() function mixes tax calculation,
180
discount logic, and database queries, making it difficult
181
to unit test and reason about.
182
183
[Helpful Solution]
184
Could we extract this into a PaymentService class? That
185
would make it testable and reusable. I can pair with you
186
on this if helpful."
187
```
188
189
### Handling Disagreements
190
191
```markdown
192
When author disagrees with your feedback:
193
194
1. **Seek to Understand**
195
"Help me understand your approach. What led you to
196
choose this pattern?"
197
198
2. **Acknowledge Valid Points**
199
"That's a good point about X. I hadn't considered that."
200
201
3. **Provide Data**
202
"I'm concerned about performance. Can we add a benchmark
203
to validate the approach?"
204
205
4. **Escalate if Needed**
206
"Let's get [architect/senior dev] to weigh in on this."
207
208
5. **Know When to Let Go**
209
If it's working and not a critical issue, approve it.
210
Perfection is the enemy of progress.
211
```
212
213
## Best Practices
214
215
1. **Review Promptly**: Within 24 hours, ideally same day
216
2. **Limit PR Size**: 200-400 lines max for effective review
217
3. **Review in Time Blocks**: 60 minutes max, take breaks
218
4. **Use Review Tools**: GitHub, GitLab, or dedicated tools
219
5. **Automate What You Can**: Linters, formatters, security scans
220
6. **Build Rapport**: Emoji, praise, and empathy matter
221
7. **Be Available**: Offer to pair on complex issues
222
8. **Learn from Others**: Review others' review comments
223
224
## Common Pitfalls
225
226
- **Perfectionism**: Blocking PRs for minor style preferences
227
- **Scope Creep**: "While you're at it, can you also..."
228
- **Inconsistency**: Different standards for different people
229
- **Delayed Reviews**: Letting PRs sit for days
230
- **Ghosting**: Requesting changes then disappearing
231
- **Rubber Stamping**: Approving without actually reviewing
232
- **Bike Shedding**: Debating trivial details extensively
233
234
## Templates
235
236
### PR Review Comment Template
237
238
```markdown
239
## Summary
240
241
[Brief overview of what was reviewed]
242
243
## Strengths
244
245
- [What was done well]
246
- [Good patterns or approaches]
247
248
## Required Changes
249
250
🔴 [Blocking issue 1]
251
🔴 [Blocking issue 2]
252
253
## Suggestions
254
255
💡 [Improvement 1]
256
💡 [Improvement 2]
257
258
## Questions
259
260
❓ [Clarification needed on X]
261
❓ [Alternative approach consideration]
262
263
## Verdict
264
265
✅ Approve after addressing required changes
266
```
267