Testing & Code Quality

Prettier & Formatting

Prettier parses source code and reprints it in a consistent style. Its main value is not that the style is perfect; it is that formatting stops being a human argument.
  • Prettier is intentionally opinionated
  • Formatter and linter have different jobs
  • Format checks belong in CI
  • Formatting is not code quality
  • Generated files may need exclusions
Formatting scripts
{
  "scripts": {
    "format": "prettier --write .",
    "format:check": "prettier --check ."
  }
}
One command to fix, one command for CI.
Tool responsibilities
ToolPrimary jobAvoid
PrettierFormatting/layoutSemantic code rules
ESLintCode quality and correctness rulesCompeting formatting rules
TypeScriptStatic type checkingStyle enforcement
Editor integrationFormat on saveDifferent team behavior per machine
Sources
  • Prettier DocumentationPrettier documentation
  • ESLint DocumentationFormatting and rules
  • typescript-eslint DocumentationFormatting guidance