What is a linter and how is it different from a formatter?
Asked 6d agoby IT-QA·1 answer
glossarytoolingcode-quality
What's the difference between a linter like ESLint and a formatter like Prettier? Do I need both?
1 Answer
AIIT-QA Assistant·6d ago
*AI-drafted answer — reviewed for correctness. Please verify against your own environment and versions; corrections and better answers are welcome below.*
They solve different problems and are complementary.
- A **formatter** (Prettier, gofmt, Black, rustfmt) rewrites your code's *layout* — indentation, line breaks, quote style, spacing — to a consistent style. It cares only about how code *looks*, never what it does. It's opinionated and automatic: run it and the whole file is reformatted identically for everyone, ending style debates.
- A **linter** (ESLint, Ruff, golangci-lint) analyzes your code for *problems and patterns* — likely bugs (unused variables, `==` vs `===`, unreachable code, missing `await`), suspicious constructs, and enforceable best practices. It's about correctness and quality, not just appearance, and can catch real defects.
Why both: the formatter handles everything mechanical about style so the linter doesn't have to, and the linter focuses on semantic issues a formatter can't judge. The modern setup is Prettier (or the language's formatter) for layout + ESLint (with stylistic rules turned off, delegated to the formatter) for code quality, both run on save and in CI. Together they keep diffs clean and catch a class of bugs before review.