DEV Community

Alex Spinov
Alex Spinov

Posted on

Prettier Has a Free Code Formatter — End Style Debates Forever

Prettier formats your code automatically. No more arguing about tabs vs spaces, semicolons, or line length. Save the file, it's formatted.

The Problem Prettier Solves

Code review comment: 'Add a trailing comma here.'
Code review comment: 'Remove the extra newline.'
Code review comment: 'Use single quotes.'

These comments waste time. Prettier eliminates ALL of them by formatting code to a consistent style automatically.

What You Get for Free

Opinionated formatting — few options, consistent output
20+ languages: JavaScript, TypeScript, CSS, HTML, JSON, Markdown, YAML, GraphQL, and more
Editor integration — format on save in VS Code, WebStorm, Vim, Emacs
CI integrationprettier --check fails if code isn't formatted
Git hooks — format only changed files with lint-staged

Quick Start

npm i -D prettier
echo '{}' > .prettierrc
Enter fullscreen mode Exit fullscreen mode

Format everything:

npx prettier --write .
Enter fullscreen mode Exit fullscreen mode

Check in CI:

npx prettier --check .
Enter fullscreen mode Exit fullscreen mode

VS Code Setup

  1. Install 'Prettier - Code formatter' extension
  2. Settings: "editor.formatOnSave": true
  3. Settings: "editor.defaultFormatter": "esbenp.prettier-vscode"

Now every save = perfectly formatted code.

The Only Config You Need

{
  "semi": true,
  "singleQuote": true,
  "tabWidth": 2,
  "trailingComma": "all",
  "printWidth": 100
}
Enter fullscreen mode Exit fullscreen mode

That's it. Prettier intentionally has few options. Less options = less debates.

With Git Hooks (lint-staged)

npm i -D husky lint-staged
npx husky init
echo 'npx lint-staged' > .husky/pre-commit
Enter fullscreen mode Exit fullscreen mode
// package.json
"lint-staged": {
  "*.{js,ts,tsx,css,md}": "prettier --write"
}
Enter fullscreen mode Exit fullscreen mode

Now: commit → only changed files get formatted → commit includes formatted code.

If your team has ANY style discussions in code reviews — install Prettier and never have them again.


Need web scraping or data extraction? Check out my tools on Apify — get structured data from any website in minutes.

Custom solution? Email spinov001@gmail.com — quote in 2 hours.

Top comments (0)