prettier
Prettier is an opinionated code formatter that enforces a consistent code style across your entire codebase by parsing and re-printing code with its own rules. …
Installation
npm install -D prettier
yarn add -D prettier
pnpm add -D prettier
Import
import * as prettier from 'prettier';
Quick Example
// .prettierrc
{
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100,
"tabWidth": 2
}
// CLI: npx prettier --write .About prettier
Prettier is an opinionated code formatter that enforces a consistent code style across your entire codebase by parsing and re-printing code with its own rules. Unlike linters that warn about style issues, Prettier automatically reformats code, eliminating all style-related discussions in code reviews. Prettier supports JavaScript, TypeScript, JSX, TSX, CSS, SCSS, Less, HTML, JSON, GraphQL, Markdown, YAML, and more through its built-in parsers and community plugins. The tool deliberately offers few configuration options — print width, tab width, tabs vs spaces, semicolons, quotes, trailing commas, bracket spacing, and a few others — enforcing a consistent style that most teams can agree on without debate. Prettier integrates with all major editors through extensions that format on save, and with CI pipelines through the --check flag that verifies formatting without modifying files. Prettier works alongside ESLint using eslint-config-prettier to disable ESLint style rules that conflict with Prettier's formatting. The tool has become essentially universal in the JavaScript ecosystem, with most popular open-source projects and companies adopting it as their standard formatter.
Quick Facts
| Package | prettier |
| Category | Build Tool |
| Weekly Downloads | 35M+ |
| License | MIT |
| Install | npm install -D prettier |
Related Packages
ESLint is the standard linting tool for JavaScript and TypeScript that analyzes your code to find an…
TypeScript is a strongly typed programming language that builds on JavaScript, adding static type de…
Husky is a tool that makes Git hooks easy to use in JavaScript projects, enabling teams to enforce c…
lint-staged is a tool that runs linters and formatters on only the files that are staged in Git, mak…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.