Prettier is, in the words of its own repository, “an opinionated code formatter” that “enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.” It was created by James Long and first released publicly in early 2017. The key word is opinionated: rather than offering a large set of style options, Prettier makes most layout decisions for you, so a team adopts the tool instead of negotiating a style guide.
What makes Prettier different from earlier reformatters is that it does not try to preserve and tidy your existing layout. Instead, as the 1.0 announcement of April 13, 2017 explains, it works “by compiling your code to an AST, and then pretty-printing the AST.” Because the original whitespace and line breaks are discarded, the output depends only on the code’s structure and Prettier’s rules, not on how the author happened to format it. The underlying algorithm draws on the classic functional-programming approach to pretty-printing, which decides where to break lines so that output fits within a target width.
Prettier spread extraordinarily quickly. By the time of the 1.0 release, only about two months after launch, the project had already amassed “~7000 GitHub stars and over 100,000 monthly npm downloads,” and it was being rolled out across large codebases at Facebook, where Long and his collaborator Christopher “vjeux” Pouzat worked. The tool resonated because, as the project puts it, it directly addresses “programmers spending a lot of time manually moving around code in their editor and arguing about styles.” Removing that work, and those arguments, was the whole selling point.
Although it began as a JavaScript formatter, Prettier grew into a multi-language tool. Its repository lists built-in support for JavaScript, TypeScript, Flow, JSX, JSON, CSS, SCSS, Less, HTML, Vue, Angular, GraphQL, Markdown, and YAML, with a plugin system for additional languages. This breadth let a single formatter cover most of the files in a typical web project, so an entire repository could be kept consistent with one tool and one command.
Prettier deliberately stays narrow: it formats, and it largely leaves bug-finding to linters such as ESLint, with which it is commonly paired. In practice teams run Prettier on save in the editor, as a pre-commit hook, and in continuous integration to reject unformatted code. Together with a shared .editorconfig for cross-editor settings, Prettier became a standard part of modern JavaScript tooling and a leading example of the opinionated-formatter philosophy that gofmt pioneered.