Dashboard

What Is a Code Formatter? Prettier and AI Agents

A code formatter rewrites code into one consistent layout. Why it matters when an AI agent and a human edit the same files.

Steve Jefferson
Steve Jefferson
Developer Advocate
23 October 20261 min read

A code formatter is a tool that rewrites your code into one consistent layout, automatically, without changing what the code does. It decides where the line breaks go, how much to indent, and whether strings use single or double quotes, so nobody has to. When an AI agent and a person both edit the same project, a formatter is what keeps the diffs showing real changes instead of spacing noise.

The same code, two layouts

Both of these do exactly the same thing:

javascript
function greet(name){ if(!name){return 'Hello'}
  return "Hello, "+name }
javascript
function greet(name) {
  if (!name) {
    return "Hello";
  }
  return "Hello, " + name;
}

The first might come from a hurried edit, the second from a formatter. If an agent writes in one style and you write in another, every file it touches can show up in review as changed, even where only the layout moved. That buries the three lines that matter under thirty that do not.

What the Prettier docs say it is for

Prettier is the most widely used formatter in the JavaScript world, and its documentation makes a clear argument. A shared style guide helps a team, but agreeing on one is slow and emotional, and an automatic formatter removes the need for those debates. It also saves the time people spend leaving style comments in code review, helps newcomers avoid spacing and syntax slips, and can reformat an entire existing codebase in one pass to make inconsistent code uniform.

The point is not that Prettier's choices are the best ones. It is that the choices are made once, by a tool, and then stop being a topic.

Formatter versus linter

These are often confused, and they are complementary.

Formatter

Linter

Job

Make layout consistent

Find likely mistakes

Changes code on its own

Yes, safely

Only for a few simple fixes

Can tell you the code is wrong

No

Often

Example

Prettier

ESLint

A formatter never judges your logic. A linter does not much care how many spaces you used. Run the formatter first, then the linter, so style issues do not clutter the lint report.

Using one with an AI agent

  1. Add a formatter to the project and commit its config, so the agent and your editor agree.

  2. Turn on format on save in your editor, so your own edits stay consistent.

  3. Run the formatter before each commit. A pre-commit hook makes this automatic.

  4. Tell the agent the project uses a formatter and to run it after editing. Many agents will otherwise guess at a style.

  5. Do the first formatting pass of an old codebase in its own commit, with no other changes, so history stays readable.

That last step matters. A formatting-only commit is easy to skim and easy to exclude when you look back for the commit that introduced a bug.

When not to bother

A throwaway script does not need one. A solo project that nobody else will read can live without it too, though adding it costs about two minutes. Once an agent starts committing to your repository, it is worth having. For the bigger picture of shipping something real, see the guide to building an app with AI.

Frequently asked questions

What does a code formatter do?

It rewrites source code into a consistent layout, covering indentation, line breaks, quotes and spacing, without changing how the program behaves.

Is Prettier a linter?

No. Prettier is a formatter. A linter such as ESLint looks for likely bugs and risky patterns, while a formatter only fixes layout.

Should I run a formatter before or after the linter?

Run the formatter first so layout noise does not clutter the lint output, then run the linter.

Why do AI agents change so many lines of code?

Often because they write in a different layout from the existing file, so a re-indented block looks like a change. A shared formatter removes that noise.

How did this land?

About the author

Steve Jefferson
Steve Jefferson

Developer Advocate

Steve builds something with Swarmz every week and writes up what worked, what broke, and what he'd do differently. Tutorials and hands-on guides are his lane.

Share

Get the next post in your inbox

One email a month. Product updates, engineering posts, and the best of Built with Swarmz.

I agree to receive emails about AI building tips and Swarmz product news. Unsubscribe any time.