Prettier — Opinionated Code Formatter for Consistent Style
Prettier is an opinionated code formatter that enforces a consistent code style across your entire codebase. It supports JavaScript, TypeScript, CSS, HTML, JSON, GraphQL, Markdown, and many more languages with minimal configuration.
Installation agent prête
Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.
npx -y tokrepo@latest install e8d0be14-366b-11f1-9bc6-00163e2b0d79 --target codexÀ exécuter après confirmation du plan en dry-run.
What it is
Prettier is an opinionated code formatter that rewrites your source files to enforce a single, consistent style. It supports JavaScript, TypeScript, CSS, HTML, JSON, GraphQL, Markdown, and many other languages through plugins.
Prettier is built for teams who want to stop arguing about tabs vs spaces, trailing commas, and line length. You configure it once, integrate it into your editor or CI pipeline, and every file follows the same rules from that point forward.
Why it saves time or tokens
Manual formatting eats developer hours. Code review comments about style waste everyone's attention. Prettier eliminates both problems by making formatting automatic and deterministic. The same input always produces the same output, so diffs stay clean and reviewers focus on logic instead of semicolons.
When working with AI coding assistants, Prettier ensures that generated code matches your project style without manual cleanup. This reduces the back-and-forth token cost of asking an LLM to reformat its output.
How to use
- Install Prettier in your project:
npm install --save-dev prettier - Create a
.prettierrcconfig file with your preferred options (or use the defaults) - Run
npx prettier --write .to format all files, or integrate with your editor for format-on-save
Example
{
'semi': false,
'singleQuote': true,
'tabWidth': 2,
'trailingComma': 'es5',
'printWidth': 80
}
With this .prettierrc, Prettier drops semicolons, uses single quotes, 2-space tabs, trailing commas in ES5-valid positions, and wraps at 80 characters.
| Option | Default | Common Override |
|---|---|---|
| semi | true | false |
| singleQuote | false | true |
| tabWidth | 2 | 4 |
| trailingComma | 'all' | 'es5' |
| printWidth | 80 | 100 or 120 |
Related on TokRepo
- AI tools for coding — browse more developer productivity tools on TokRepo
- Automation tools — formatters, linters, and CI helpers curated on TokRepo
Common pitfalls
- Running Prettier without a
.prettierignorecan reformat generated files, vendor code, or build artifacts you did not intend to touch - Combining Prettier with ESLint style rules causes conflicts; use
eslint-config-prettierto disable overlapping ESLint rules - Forgetting to add Prettier to your CI pipeline means developers who skip editor integration will push unformatted code
Questions fréquentes
Prettier natively supports JavaScript, TypeScript, JSX, TSX, CSS, Less, SCSS, HTML, JSON, GraphQL, Markdown, and YAML. Additional languages like PHP, Ruby, Java, and XML are available through community plugins. The plugin API lets anyone add a parser and printer for new languages.
ESLint finds bugs and enforces code-quality rules like no-unused-vars or no-implicit-globals. Prettier only handles formatting: indentation, line breaks, quote style, and spacing. They complement each other. Use eslint-config-prettier to disable ESLint rules that conflict with Prettier formatting.
Yes. AI assistants often produce code with inconsistent formatting. Running Prettier on generated output normalizes style instantly. Many editors run Prettier on save, so AI-generated code is reformatted the moment you paste it. This saves tokens you would otherwise spend prompting the model to fix style.
Yes. Install the Prettier VS Code extension, set Prettier as your default formatter in settings, and enable format-on-save. Every time you save a file, Prettier rewrites it to match your config. This works for all supported languages without additional setup beyond the extension.
Create a `.prettierignore` file in your project root. The syntax is identical to `.gitignore`. Common entries include build output directories like dist/ and node_modules/, generated files, and vendor code. You can also use `prettier-ignore` comments inline to skip specific blocks of code.
Sources citées (3)
- Prettier GitHub— Prettier supports JavaScript, TypeScript, CSS, HTML, JSON, GraphQL, Markdown and…
- Prettier Docs— Prettier is an opinionated code formatter
- eslint-config-prettier GitHub— eslint-config-prettier disables ESLint rules that conflict with Prettier
En lien sur TokRepo
Fil de discussion
Actifs similaires
Standard — Zero-Config JavaScript Style Guide and Linter
Standard is an opinionated JavaScript linter and formatter that enforces consistent code style with no configuration required, catching bugs and eliminating style debates.
SwiftFormat — Opinionated Swift Code Formatter
A command-line tool and Xcode extension for automatically formatting Swift code according to configurable style rules.
YAPF — Yet Another Python Formatter by Google
An opinionated Python code formatter that reformats code to the best formatting that conforms to a configured style, even if the original code did not violate the style guide.
Drizzle ORM — TypeScript SQL That Feels Like Code
Type-safe TypeScript ORM with SQL-like syntax. Zero overhead, serverless-ready, supports PostgreSQL, MySQL, SQLite. Schema as code with automatic migrations. 28,000+ GitHub stars.