A code formatter is a tool that automatically rewrites source code into one consistent layout, controlling indentation, spacing, quotes, line length and line breaks. Examples include Prettier, Black for Python, gofmt for Go and rustfmt for Rust.
Why it matters
Consistent formatting makes code easier to read and keeps diffs small, because changes show real edits instead of whitespace noise. Opinionated formatters remove style arguments from code review entirely: the tool decides, and everyone's code looks alike. Many teams run the formatter on save and again in a pre-commit hook or CI check so unformatted code cannot be merged. A formatter changes only layout, not behavior.
Example
Before:
const sites=[ 'a','b' ]; function f(x){return x+1}
After running Prettier:
const sites = ["a", "b"];
function f(x) {
return x + 1;
}
Common mistakes
- Formatting an entire legacy codebase in one commit that hides real history; use a blame-ignore file.
- Running a formatter and a linter with conflicting style rules.
- Different team members using different versions or configurations.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.