A formatter rewrites code into a canonical layout. Indentation, line breaks, trailing commas, quote style — all decided by the tool, the same way, every time. The team stops arguing about style; PRs stop containing reformatting noise; new contributors save hours of "is this right?" anxiety. The cost is one config decision; the benefit is permanent.
← Back to Testing| Stack | Formatter(s) | Notes |
|---|---|---|
| JavaScript / TypeScript | Prettier, Biome | Prettier is the standard. Biome is Rust-based, faster, lint+format combined. |
| Python | Black, Ruff Format | Ruff Format is Black-compatible and dramatically faster — increasingly the default. |
| Go | gofmt (built-in) | The original opinionated formatter. go fmt is part of the toolchain. |
| Rust | rustfmt | Standard, opinionated, included with the toolchain. |
| Java / Kotlin | Spotless, google-java-format, ktlint, ktfmt | Spotless is a Gradle plugin orchestrating multiple formatters. |
| .NET (C#) | dotnet format, CSharpier | CSharpier is Prettier-style for C#. |
| Ruby | RuboCop, Rufo, Standard | RuboCop with auto-correct serves as both linter and formatter for many. |
| Swift | swift-format, SwiftFormat | swift-format is Apple's; SwiftFormat is the popular community tool. |
| PHP | PHP-CS-Fixer, Pint | Pint is Laravel's wrapper around PHP-CS-Fixer. |
| SQL | SQLFluff, pgFormatter | SQLFluff also lints; pgFormatter is Postgres-specific. |
| Markdown / YAML / Terraform | Prettier (md), yamlfmt, terraform fmt | Don't ship inconsistent docs and config either. |
Editor integration is mandatory. VSCode, IntelliJ, Vim, Neovim, Emacs — every modern editor has format-on-save for the major formatters. Files are clean by the time they hit git. Reviewers never see unformatted code.
For when format-on-save is forgotten. pre-commit, Husky, lefthook reformat in place at commit time. CI runs prettier --check / black --check / gofmt -l as a fail-on-diff. The two together catch every case.
Don't tweak the formatter. Five-team companies have wasted entire weeks debating singleQuote: true vs false. The point of the tool is "you don't decide." Pick the defaults; move on.
When introducing a formatter to a legacy codebase, do it in one dedicated commit. Add the SHA to .git-blame-ignore-revs so git blame still shows real authors. Don't sprinkle reformatting across feature PRs — it pollutes diffs forever.
If the linter and the formatter disagree, every save toggles back and forth. ESLint + Prettier integrations (eslint-config-prettier) turn off ESLint style rules that conflict with Prettier. Use them.
.prettierrc turns the formatter into a linter and re-introduces style debates. Resist..git-blame-ignore-revs. Reformat commit shows up as "Bob touched every line"; the actual author info is one commit deeper. The ignore file fixes this.