Part of my role at Accenture is to review code and mentor junior developers. I expected it to be about finding bugs. Mostly, it taught me how to write code and comments that other people can follow.
Read the description first
Before the diff, I read what the pull request is for. If the description is empty, that is my first comment. I ask for three things: what changed, why, and how to test it. A reviewer who does not know the goal can only review style.
Run it
Five minutes with the branch running finds things that a diff never shows: a layout that breaks at phone width, a loading state that flashes, a button that does nothing on the second click.
Label every comment
I start each comment with what kind of comment it is:
- Must fix: a bug, a security problem, or a break from a rule that the team agreed on.
- Suggestion: a better way, but the current way works.
- Question: I do not understand something. Often the code is fine and needs a better name or a comment.
- Nit: a small style point. If it comes up twice, it becomes a lint rule.
Without labels, a new developer treats every comment as an order, and fixes the nits first.
Ask, then explain
“Why is this in a useEffect?” teaches more than “Move this out of the useEffect.” Sometimes the answer is a reason that I did not know. When it is not, I explain the rule and link the docs, for example React's page You Might Not Need an Effect. Then the next pull request gets it right without me.
Turn repeated comments into tools
If I write the same comment three times, it is not a review comment any more. It becomes one of these:
- An ESLint rule, for example
react-hooks/exhaustive-deps. - A Prettier setting, so nobody argues about formatting.
- A line in the pull request template.
- A shared component, when people keep building the same thing in different ways.
Pair on the first few
For a new joiner, the first two or three reviews happen on a call. We read the diff together, and they explain their choices. It takes longer once, and it saves a week of comments back and forth.
Say what is good
When something is well done, I say so, and I say why: “Nice, this hook makes the component easy to test.” People repeat what you point out.
What it changed in my own code
- I write the pull request description before I ask for a review.
- I keep pull requests small, because I know how hard a 1,000-line diff is to review.
- I name things for the reader, not for me.
- Where the code does something surprising, I leave a comment that says why.