A reviewer opens your pull request and meets a wall. One function arrives as a single line that runs off the edge of the screen, another is indented at three different depths, and the diff view highlights whole blocks where nothing changed except spacing. The reviewer now has two jobs: decode the layout first, then hunt for the logic underneath it. Layout noise wins that contest often enough that real changes slip past tired eyes, and the feedback round fills up with comments about commas and indentation instead of the behaviour you actually wanted checked.
Formatting before you commit removes the first job entirely. This guide shows how to prepare JavaScript for review with the free JavaScript Formatter on Ovatly, which turns compressed or messy code into consistently indented code with one statement per line. It also covers the honest limits: the tool enforces one standard style, and it knows nothing about your team's lint rules, your logic, or your syntax.
Contents
- Quick answer
- Why diffs punish inconsistent formatting
- What the formatter standardizes
- How to format before you commit, step by step
- Worked example: one line becomes a reviewable diff
- Limitations and alternatives
- Common mistakes
- FAQs
- Conclusion
Quick answer
Run your code through the JavaScript Formatter before you commit it. Paste the JavaScript in, choose the indent size your team already uses, 2 or 4 spaces, and press Format JavaScript. The code comes back with one statement per line, even indentation, and standard spacing around operators and after commas, ready to copy or download. Commit that formatted shape, so the pull request diff shows your logic changes and nothing else. The formatter changes only whitespace, line breaks and spacing; it does not check logic or syntax, and it works on plain JavaScript only.
Why diffs punish inconsistent formatting
A pull request is not read like a file. It is read as a diff, and a diff works line by line: a changed line is shown as a removal next to an addition, and an untouched line is shown as context. That model rewards code where one line holds one statement, because a one-word logic change then appears as exactly one changed line. It punishes code where a whole function sits on a single line, because changing one character inside it marks the entire line as rewritten, and the reviewer has to compare two long strings character by character to find what moved.
Uneven indentation does similar damage at a larger scale. When one block is indented by two spaces, the next by four, and a third by a tab, the diff view cannot present the nesting cleanly, and blocks that were merely re-indented light up as if they were rewritten. Reviewers learn to distrust those highlights, and distrust slows everything down. The fix is boring and complete: submit every file in one consistent shape, so the only lines that light up are the lines whose logic actually changed.
What the formatter standardizes
The formatter works on the layout of your code, not its meaning. It takes compressed or messy JavaScript and lays it out with consistent indentation, one statement per line. Semicolons and braces are placed in a standard style, and spacing around punctuation is standardized, which covers the small inconsistencies that creep in when code is written quickly or copied from somewhere else: a missing space after a comma here, an operator hugging its operands there.
Because only whitespace, line breaks and spacing change, formatting is safe to apply right before a commit. Your logic is never changed, and the behaviour of the code is untouched. One deliberate exception is worth knowing: template literal contents are literal text, so the formatter leaves them exactly as written. A long template literal stays on its line rather than being reflowed, because reflowing it would change the text it produces.
How to format before you commit, step by step
- Finish the change and make sure the code runs. Formatting is the last step before committing, not a substitute for testing.
- Open the JavaScript Formatter and paste your JavaScript into the input box.
- Choose an indent size of 2 or 4 spaces, matching the convention your team already uses.
- Press Format JavaScript.
- Copy the formatted code, or download it, and put it back in your file exactly as it came back.
- Commit that shape. The formatted version is the version the reviewer should see, so do not hand-tidy parts of it afterwards.
Worked example: one line becomes a reviewable diff
Take the kind of compact function that shows up in copied samples and quick fixes:
function add(a,b){return a+b;}
Submitted as-is, that line is the whole diff unit. If a reviewer later changes the function to add a third value, the entire line is struck through and rewritten, and the actual change hides inside it. Formatted with a 2-space indent, the same code comes back as:
function add(a, b) {
return a + b;
}
Nothing about the logic changed: same function, same parameters, same return. What changed is the shape. Now the signature sits on its own line, the return statement sits on its own line, and a future edit to either one shows up as a single, readable diff line. Multiply that by every function in a real pull request and the review stops being an exercise in squinting.
Limitations and alternatives
The formatter enforces one standard style, and that is both its strength and its boundary. It does not know your team's lint rules, so if your project has agreed on a house style that differs from the standard layout, the team's own tooling is the authority and this formatter is a quick option for code outside that pipeline. Agree the style with the team first; the goal is one shape everyone submits, not a new shape imposed during someone else's review.
It also does not check logic or syntax. Formatting does not fix syntax errors, and badly broken code may format strangely or be rejected, so broken code needs fixing before it needs formatting. The tool works on plain JavaScript only: JSX components and TypeScript annotations are not supported. And while it will format whatever you paste, a large production bundle is better handled by your editor's formatter or a source map in devtools; this is a paste tool for files and snippets, not a build step.
Common mistakes
- Reformatting a teammate's code mid-review. Running someone else's files through a formatter during your own change buries your work under hundreds of layout-only diff lines. Format the code you are submitting, and leave unrelated files alone.
- Formatting after committing, then amending quietly. If the committed shape and the reviewed shape differ, the next diff starts from a version nobody reviewed. Format first, commit the result.
- Mixing indent sizes between files. Two spaces in one file and four in the next recreates the inconsistency the formatter exists to remove. Pick the team's size and use it everywhere.
- Expecting the formatter to validate the code. It lays out what you give it. Syntax errors and logic bugs pass through untouched, so run and test the code before formatting it.
- Hand-editing the formatted output. Small manual tweaks after formatting reintroduce one-off shapes. If something looks wrong, fix the code and format it again.
FAQs
Does formatting change what my code does? No. Only whitespace, line breaks and spacing around punctuation change. Semicolons and braces are laid out in a standard style, and your logic is never changed.
Which indent size should I pick, 2 or 4 spaces? The one your team already uses. The point of formatting for review is consistency with the rest of the codebase, so match the existing convention instead of introducing your own.
Will the formatter catch bugs before review? No. It does not check logic or syntax, and formatting does not fix syntax errors. Badly broken code may format strangely or be rejected, so make sure the code runs before you format it.
Can I format JSX or TypeScript for a review? No. The formatter works on plain JavaScript. JSX components and TypeScript annotations are not supported.
Why did a long template literal stay on one line? Template literal contents are literal text, so the formatter leaves them exactly as written instead of reflowing them.
Conclusion
A good pull request asks one question: what did you change, and why? Formatting before you commit makes sure the diff answers that question instead of raising layout questions of its own. Run your JavaScript through the JavaScript Formatter, match your team's indent, and commit the shape that comes back. When the question is not how your own code should look but which of the two standard shapes a file should be in at all, the companion guide on beautified vs minified code covers when each form wins, and the rest of this series lives in the Developer Tools guides archive.