
Opinionated Code Formatter
Free

Prettier is an opinionated code formatter that enforces a consistent style by parsing code and re-printing it from scratch with its own rules. Unlike traditional linters that focus on error detection, Prettier ignores previous styling, ensuring that codebases remain uniform regardless of the original author's habits. It supports a vast ecosystem including JavaScript, TypeScript, CSS, HTML, and GraphQL. By automating the formatting process, it eliminates 'style bikeshedding' in code reviews, allowing developers to focus on logic rather than indentation or semicolon placement. It is the industry standard for maintaining high-velocity, multi-contributor repositories.
Prettier discards original styling and reconstructs code based on an internal AST (Abstract Syntax Tree). By enforcing a strict set of rules, it eliminates subjective debates over brace placement or line length. This deterministic approach ensures that every file in a project looks identical, reducing cognitive load for developers switching between modules.
Beyond JavaScript and TypeScript, Prettier supports CSS, HTML, JSON, Markdown, YAML, and GraphQL. This unified toolchain means developers don't need separate formatters for different file types. It handles complex nesting in languages like SCSS or MDX with the same consistency, providing a single source of truth for project-wide styling.
Prettier provides first-class plugins for VS Code, WebStorm, Vim, and Emacs. By hooking into the editor's 'Format on Save' lifecycle, it provides instantaneous feedback. This tight integration ensures that code is formatted before it is even committed to version control, preventing messy diffs and maintaining clean git history.
Prettier ships with sensible defaults that work for 95% of projects out of the box. While it allows for minor configuration (like tab width or semicolon usage), it intentionally limits options to prevent 'configuration bloat.' This philosophy forces teams to accept a standard, preventing the endless customization cycles common with ESLint-based formatting rules.
By running `prettier --check` in a CI pipeline, teams can automatically reject pull requests that contain unformatted code. This gatekeeping mechanism ensures that no developer can bypass the team's style guide, maintaining 100% compliance across the entire repository without manual intervention from maintainers.
npm install --save-dev --save-exact prettier.,2. Create an empty configuration file to signal usage: echo {}> .prettierrc.json.,3. Create a .prettierignore file to exclude build artifacts like dist, coverage, and node_modules.,4. Add a format script to your package.json: "format": "prettier --write \"src/**/*.js\"".,5. Integrate with your IDE (VS Code, WebStorm) by installing the official Prettier extension and enabling 'Format on Save'.,6. Run npm run format to standardize your entire codebase in a single pass.In large enterprise teams, developers often have conflicting coding styles. By integrating Prettier, the team removes style-related comments from code reviews, allowing senior engineers to focus on architectural logic rather than syntax, significantly increasing the velocity of the PR review process.
When inheriting a legacy codebase with inconsistent formatting, developers can run Prettier across the entire project to normalize the syntax. This provides a clean baseline, making it easier to read the code and identify actual bugs without being distracted by inconsistent indentation or spacing.
Technical writers and developers use Prettier to format Markdown files, ensuring that tables, lists, and code blocks are consistently aligned. This is particularly useful for documentation-heavy repositories where readability is critical for end-users and contributors.
They manage complex JS/TS/CSS stacks and need to ensure that code remains readable and consistent across large-scale applications, reducing the friction of collaborative development.
They receive contributions from developers with varying skill levels and styles. Prettier acts as an automated gatekeeper, ensuring all incoming code matches the project's standards.
They implement CI/CD pipelines and require automated tools to enforce code quality standards, ensuring that only correctly formatted code is merged into production branches.
Open source project licensed under the MIT License. Completely free to use, distribute, and modify for both personal and commercial projects.