LLMpediaThe first transparent, open encyclopedia generated by LLMs

Prettier (code formatter)

Generated by DeepSeek V3.2
Note: This article was automatically generated by a large language model (LLM) from purely parametric knowledge (no retrieval). It may contain inaccuracies or hallucinations. This encyclopedia is part of a research project currently under review.
Article Genealogy
Parent: TypeScript Hop 4
Expansion Funnel Raw 80 → Dedup 43 → NER 5 → Enqueued 5
1. Extracted80
2. After dedup43 (None)
3. After NER5 (None)
Rejected: 38 (not NE: 38)
4. Enqueued5 (None)
Prettier (code formatter)
NamePrettier
DeveloperJames Long, Christopher Chedeau, and contributors
Released11 January 2017
Programming languageJavaScript
Operating systemCross-platform
GenreCode formatter
LicenseMIT License
Websitehttps://prettier.io

Prettier (code formatter) is an opinionated code formatter designed to enforce a consistent code style across a project by parsing code and reprinting it with its own rules. Initially created for JavaScript, it has expanded to support a wide array of programming languages, markup languages, and style sheet languages. The tool is maintained as an open-source project primarily by developers James Long and Christopher Chedeau, with significant contributions from the community on GitHub.

Overview

Prettier was first publicly released in January 2017 by James Long, a developer then working at Facebook. The project emerged from frustrations with code style debates and the limitations of existing linters like ESLint for formatting. Its core philosophy is to eliminate all developer decisions about formatting by taking the parsed abstract syntax tree and outputting code formatted according to a predetermined, opinionated style guide. This approach has made it popular within the JavaScript ecosystem and companies like Facebook, Airbnb, and Spotify.

Features

The primary feature of Prettier is its ability to format code automatically, handling aspects like indentation, semicolon usage, quotation marks, and line length. It operates on a "pretty printing" algorithm that ensures the output is both syntactically correct and stylistically uniform. Key capabilities include support for JavaScript ES6 features, JSX syntax popularized by React, and intelligent handling of comments. Unlike linters such as ESLint or JSHint, it does not report stylistic errors but instead rewrites the code directly.

Supported languages and tools

Prettier supports a broad and growing list of languages and file formats through its plugin system and built-in parsers. Core supported languages include JavaScript, TypeScript, Flow, JSX, JSON, and CSS. Extended support via community plugins encompasses HTML, Vue, Angular, Markdown, YAML, and GraphQL. It integrates with the parsers of tools like Babel and PostCSS to understand modern syntax, and its Node.js runtime allows it to be used in most development environments.

Configuration and usage

Configuration is intentionally minimal, emphasizing consistency, but options can be specified via a JSON configuration file (`.prettierrc`), API parameters, or CLI flags. Common settings adjust the print width, tab width, use of semicolons, and choice between single and double quotes. It can be run via its command-line interface on individual files or entire directories, integrated into npm scripts, or executed as part of a Git pre-commit hook using tools like Husky and lint-staged.

Integration with development tools

Prettier is deeply integrated into the modern software development workflow. Most popular code editors and integrated development environments, including Visual Studio Code, WebStorm, Sublime Text, and Vim, offer extensions that format code on save. It is commonly paired with version control hooks via Husky to ensure all committed code is formatted. Within continuous integration pipelines on platforms like GitHub Actions, GitLab CI/CD, and Jenkins, it can be used to check formatting compliance.

Community and adoption

The project is hosted on GitHub under the MIT License and has garnered widespread adoption, evidenced by its tens of thousands of stars and use by major organizations like Microsoft, Netflix, and PayPal. The community contributes through issue reporting, plugin development, and translations of its documentation. Its adoption has influenced the configuration defaults of other tools and reduced the prevalence of code review debates over style in many open-source projects and corporate codebases, particularly those using React and Node.js.

Category:Code formatters Category:JavaScript programming tools Category:Free software programmed in JavaScript Category:2017 software