Code Formatting: Beautify, Minify & Diff
Beautifiers, auto-formatters, minifiers and diffs, with measurements: Prettier settled 87 of 87 real JavaScript files in one pass and js-beautify 83, minification plus Brotli shrank lodash from 544 KB to 22 KB, and stripping formatting cut model input tokens by 24.5% in a 2025 study.
What Formatting Does, and What the Evidence Says
Formatters change whitespace, line breaks and punctuation style without changing what code does; minifiers remove everything a machine does not need; diff tools show what changed. The case for consistent formatting is mostly practical: when a tool owns the layout, reviews and diffs show logic changes instead of style churn. Claims that formatting makes code a fixed percentage faster to understand are hard to support, because the controlled studies of indentation have produced mixed results, and comprehension measures themselves vary between studies.
Formatting does have a measurable cost in one new place. Pan and colleagues (2025, found through alphaXiv) removed indentation and newlines from code given to ten language models across Java, Python, C++ and C#: input tokens fell by 24.5% on average while code-completion performance held. Whitespace that helps people is overhead for a model, which is worth knowing if you paste large files into one.
Beautifiers and Auto-Formatters
A beautifier re-indents and re-wraps code. Our Code Beautifier runs js-beautify 1.15.1, and when we rebuilt it we checked that formatting never changes meaning: 300 real JavaScript files kept an identical token sequence, and 66 stylesheets and 40 HTML fragments rendered the same. Prettier goes further: it reprints the whole file from its syntax tree with very few options, which is why teams adopt it to end style debates.
One property worth checking in any formatter is idempotence: formatting already formatted code should change nothing, or every save produces noise in version control. We formatted 87 real JavaScript files from npm packages twice with each tool. Prettier 3.6.2 was idempotent on all 87; js-beautify on 83 of 87, so a second pass still moved a few lines in 4 files. For a one-off cleanup that does not matter; for a format-on-save setup in a team, use a formatter that settles in one pass.
Prettier and ESLint Today
Older guides describe ESLint as a formatter plus linter. ESLint deprecated its core formatting rules in version 8.53.0, released November 3, 2023, and recommends a dedicated source code formatter instead. The common setup is now Prettier, or another formatter, for layout and ESLint for correctness rules, both run on save or in a pre-commit hook so formatting never reaches review.
Minification and Compression
Minifiers strip comments and whitespace and, for JavaScript, shorten local names; compression then removes most of the remaining repetition on the wire. In our minification tests, lodash 4.17.21 went from 544 KB raw to 71 KB with terser and 22 KB after Brotli, and jQuery 3.7.1 from 285 KB to 87 KB and then 28 KB. Bootstrap's CSS barely shrank from minification (281 KB to 233 KB) but compressed to 23 KB, so for stylesheets compression does most of the work. Use the Code Minifier for quick jobs and a build tool for production.
Diffs and Formatting Churn
A diff is only as useful as its signal-to-noise ratio. Reformatting a file and changing its logic in the same commit buries the logic change in hundreds of whitespace lines, so format in a separate commit, or have the formatter run before every commit so there is never a backlog. The Text Diff tool compares two versions line by line in the browser.
Formatting SQL Safely
SQL formatters have one rule that matters more than any style choice: they must never touch string literals, quoted identifiers or comments, because changing the text inside quotes changes what a query returns. Before trusting a SQL formatter, run a query with a string such as 'a, b c' and a -- comment through it and compare the results of the original and formatted queries.
- [1]Pan D, Sun Z, Zhang C, Lo D, Du X (2025), The Hidden Cost of Readability: How Code Formatting Silently Consumes Your LLM Budget, arXiv:2508.13666 (via alphaXiv) ↗
- [2]ESLint blog (Oct 26, 2023), Deprecation of formatting rules (v8.53.0) ↗
- [3]Prettier documentation, Rationale and option philosophy ↗
- [4]js-beautify 1.15.1 (MIT) ↗