Article illustration 1

The Genesis of an Unlikely Peacemaker

In 2017, a quiet revolution began in JavaScript ecosystems worldwide. Prettier—now installed in over 83% of JS projects—didn't just reformat code; it extinguished the decades-old "Tabs vs. Spaces" holy war. Its origin story starts not in Silicon Valley, but in a French computer science classroom at EPITA. Founder James Long faced draconian formatting rules: every deviation meant losing 2 points out of 20. "10 formatting issues and you're getting a zero," he recalls. This brutal education planted the seed: could machines handle this tedious work?

Years later at Facebook, the problem resurfaced when code reviews devolved into formatting nitpicks. Colleagues like Yuan Tian wasted hours manually correcting brace placements and indents. Existing linters failed because they operated on rules, not holistic design. As Long explains: "Rule-based approaches break down on line-length decisions. They don’t converge—fixing one violation often creates another."

Article illustration 2

Why Previous Formatters Failed

The landscape was littered with attempts. Go’s gofmt (2009) succeeded by mandating formatting from day one, while Dart’s dartfmt used a complex "beauty-scoring" algorithm Long deemed impractical: "Optimizing AST layouts requires exploring exponential states. Humans can’t predict why it chooses a format."

JavaScript formatters faced a Pareto paradox: building 80% of the solution took 20% effort, but the remaining 20% required 80% more work. "You can’t ship if it breaks every fifth line," Long emphasizes. "Developers are viscerally attached to their code’s appearance."

The Breakthrough: Snapshot Testing & Wadler’s Algorithm

In late 2016, collaborators James Long and Pieter Vanderwerff began prototyping. Critical to their progress? Jest snapshot testing. "Instead of manual string comparisons," Long notes, "we auto-generated output diffs. One command updated all tests." This allowed rapid iteration on edge cases.

Long adopted the JavaScript version of Long’s prototype (over Vanderwerff’s ReasonML implementation) and unearthed the core innovation: Philip Wadler’s 2003 paper "A Prettier Printer." Its elegance stunned him: "Just 23 commands—group, indent, softline—handled all of JS, CSS, and HTML." The algorithm builds a document tree, then flattens it optimally within line-length constraints.

The 99.999% Problem: Correctness Over Beauty

Article illustration 3

Prettier’s existential threat wasn’t formatting preferences—it was correctness. A misplaced parenthesis could break code. Long’s solution? Idempotency: prettier(input) === prettier(prettier(input)). "Most bugs violated this," he says. For six months, he "lived in a submarine," grinding through Facebook’s monorepo, fixing failures until correctness hit zero.

Four contentious decisions defined adoption:
1. Semicolon insertion: Printed leading semicolons to avoid ASI pitfalls:

let range = getRange()
;[start, end] = range // Semicolon prevents catastrophe
  1. Object literals: Broke idempotency—expanded objects if they contained newlines
  2. Method chaining: Required 500 lines of heuristics for diverse patterns like jQuery chains
  3. Comments: Became "the bane of my existence" due to arbitrary placement

The Nuclear Option: How Facebook Adopted Prettier

Rollout required psychological and technical finesse. Long enforced zero mandatory reformats. Instead, files opted in via a @format header. "I refused to reformat a single line myself. People had to want it." The carrot: IDE auto-formatting eliminated manual linting. The stick: CI blocked unformatted changes. Within a year, 75% of Facebook’s code used it. Only one production bug emerged—from a header-comment mishap during bulk adoption.

The Unfunded Foundation

Article illustration 4

Despite industry-wide dependence, Prettier survives on modest Open Collective donations—just $200k over 8 years. Maintainers Fisker Cheung and Sosuke Suzuki receive $1.5k/month. "There’s no value exchange," Long laments. "Companies won’t pay for free tools." Meta funds Long’s work, but broader sustainability remains unsolved.

The Legacy: A Post-Formatting World

By 2021, Prettier dominated the State of JS survey so completely that the question was retired. Its ethos birthed Python’s Black and inspired formatters for most languages. The holy war ended not through conquest but obsolescence. When machines handle formatting, preferences become config flags. Developers now focus on what matters: logic over layout.

As Long ships his next venture, he leaves a transformed landscape: "It’s surreal that I decided how millions of lines of code look. But the real win? Freeing brains for harder problems."


Source: Birth of Prettier by James Long