Code formatting
Formatting debates are the cheapest possible way to spend a team's
attention: everyone has a preference, none of them affect behavior, and the
argument recurs on every pull request. The escape is to hand the whole
question to a tool with almost no options, run it automatically, and never
discuss brace placement again.
Method
- Pick one opinionated formatter and take its defaults. Prettier for
JS/TS, Black for Python, gofmt for Go, rustfmt for Rust, spotless or
ktlint for Kotlin/Java. The point is to remove choices, so do not spend
the meeting tuning line width past the default (Black 88, Prettier 80).
- Format the whole repo in one commit. Run the formatter across every
file, commit it alone with a message like "Apply Black", and add that
SHA to
.git-blame-ignore-revs so git blame skips the reformat and
still points at the real author of each line.
- Enforce in CI, not by asking. Add
black --check, prettier --check, or gofmt -l as a pipeline step that fails on any unformatted
file. A check that lives only in a reviewer's head gets skipped the week
they are busy.
- Format on save and on commit. Wire the formatter into editor "format
on save" and a pre-commit hook (pre-commit, or husky with lint-staged)
so files are correct before they are ever pushed. CI becomes the
backstop, not the first line of defense.
- Keep formatting out of feature diffs. Never let a reformat ride
along in a behavior change: the reviewer cannot find the two lines that
matter under two hundred that only moved. Reformat in its own PR, then
build on the clean base.
- Pin the formatter version. Lock the exact version in the lockfile or
tool config so two developers on different releases do not fight over a
rule that changed between them. Upgrade deliberately, in its own commit.
Litmus tests
- Does a fresh clone plus one command format identically on every machine?
- Can a reviewer read any diff with no formatting-only lines in the way?
- Does
git blame on a reformatted line show the author, not the reformat
commit?
Boundaries
Formatters own whitespace and layout, not naming, structure, or clarity:
those belong to review and to linting. Where a language has no dominant
formatter, a documented editorconfig plus a lint rule set is the fallback,
and consistency within the repo outranks which style would have won an
argument.
1---2name: code-formatting3description: Hand formatting to an opinionated tool run automatically so the team stops arguing style and diffs stay readable. Use when adopting a formatter, onboarding a repo, or cleaning up noisy review diffs.4---56# Code formatting78Formatting debates are the cheapest possible way to spend a team's9attention: everyone has a preference, none of them affect behavior, and the10argument recurs on every pull request. The escape is to hand the whole11question to a tool with almost no options, run it automatically, and never12discuss brace placement again.1314## Method15161. **Pick one opinionated formatter and take its defaults.** Prettier for17 JS/TS, Black for Python, gofmt for Go, rustfmt for Rust, spotless or18 ktlint for Kotlin/Java. The point is to remove choices, so do not spend19 the meeting tuning line width past the default (Black 88, Prettier 80).202. **Format the whole repo in one commit.** Run the formatter across every21 file, commit it alone with a message like "Apply Black", and add that22 SHA to `.git-blame-ignore-revs` so `git blame` skips the reformat and23 still points at the real author of each line.243. **Enforce in CI, not by asking.** Add `black --check`, `prettier25 --check`, or `gofmt -l` as a pipeline step that fails on any unformatted26 file. A check that lives only in a reviewer's head gets skipped the week27 they are busy.284. **Format on save and on commit.** Wire the formatter into editor "format29 on save" and a pre-commit hook (pre-commit, or husky with lint-staged)30 so files are correct before they are ever pushed. CI becomes the31 backstop, not the first line of defense.325. **Keep formatting out of feature diffs.** Never let a reformat ride33 along in a behavior change: the reviewer cannot find the two lines that34 matter under two hundred that only moved. Reformat in its own PR, then35 build on the clean base.366. **Pin the formatter version.** Lock the exact version in the lockfile or37 tool config so two developers on different releases do not fight over a38 rule that changed between them. Upgrade deliberately, in its own commit.3940## Litmus tests4142- Does a fresh clone plus one command format identically on every machine?43- Can a reviewer read any diff with no formatting-only lines in the way?44- Does `git blame` on a reformatted line show the author, not the reformat45 commit?4647## Boundaries4849Formatters own whitespace and layout, not naming, structure, or clarity:50those belong to review and to linting. Where a language has no dominant51formatter, a documented editorconfig plus a lint rule set is the fallback,52and consistency within the repo outranks which style would have won an53argument.