Frontend Utilities intermediate 12 min

Clean Up a Snippet Before Reviewing It

Format code before reviewing behavior so style noise does not hide the real issue.

Scenario

A teammate pastes a JavaScript snippet into chat as a single line and asks "does this look right?" Reviewing one-line code is a trap: the else branch, the object being sent, and the guard condition all blur together, and the reviewer approves the intent instead of the code. Format first — logic review only counts when you can see the control flow.

Broken input

if(user&&user.active){send({id:user.id,name:user.name})}else{throw new Error('inactive')}

Goal

Use Code Formatter to expand the snippet with Prettier before judging it. Formatting is semantically neutral, so anything that looks different afterwards was always there — you just could not see it.

Tool sequence

  1. Open Code Formatter.
  2. Paste the one-liner and format it as JavaScript.
  3. Read the expanded control flow: a guard on user && user.active, a send with a two-field object, and a throwing else branch.
  4. Now review the logic questions the one-liner was hiding: should an inactive user really throw, and is user.name guaranteed when user.active is true?
  5. Post the formatted version back into the review thread so the discussion happens on readable code; if the snippet was HTML or SQL, the same first step applies via HTML Formatter or SQL Formatter.

Checkpoint output

if (user && user.active) {
  send({ id: user.id, name: user.name });
} else {
  throw new Error("inactive");
}

Branches, payload shape, and error path each sit on their own lines — the snippet is now reviewable, and the remaining questions are about behavior, not layout.

Common mistakes

  • Reviewing logic while formatting noise is still in the way and approving what you assume the code says.
  • Changing behavior while "cleaning up" — reformatting and refactoring are different operations.
  • Forgetting to re-format after a small manual edit, so the version pasted back is half-styled.
  • Formatting with different settings than the target repo and generating a spurious diff.

Related tools and lessons