Formatting and reproducible code style
Quick answer
A formatter applies consistent source layout. Prettier supports checking formatted output separately from writing changes, while linting and testing address other quality concerns.
Tooling examples
Example 1. Context: projects/lint-lab. Run in a fresh prepared fixture copy; see its README. Manual integration example — not executed here.
npm run format:checkExpected observation: Expected nonzero exit while messy.js differs from configured formatting.
Example 2. Context: projects/lint-lab. Run in a fresh prepared fixture copy; see its README. Manual integration example — not executed here.
npm run format:writenpm run format:checkExpected observation: Expected check success after formatter rewrites the target file.
How the tooling works
Pin the formatter version in development dependencies and commit shared configuration. prettier --check reports files that differ from the formatted result; --write updates files. Prefer --check in CI and use --write on reviewed working copies. Exclude generated artifacts deliberately. Align linter and formatter settings to avoid competing style rules. Formatting aims to preserve meaning; test changes when transforming code or using plugins. The lint-lab contains a formatter setup template, but Prettier is not installed here.
Common mistakes
Do not mix a repository-wide formatting rewrite with a small behavior change if a separate diff would be easier to review.
Practice
Run format:check on messy.js after installing a pinned Prettier, then run format:write in a disposable copy and repeat the check.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Formatting and reproducible code style — Knowledge Check
Assess tooling contracts, diagnostic reasoning and transfer to a project.
Which Prettier operation is suitable for CI without editing source files?
What does a successful formatting check establish?
Why pin the formatter version?
In Formatting and reproducible code style, what is the expected observation for example 1 in its documented setup? npm run format:check
In Formatting and reproducible code style, what is the expected observation for example 2 in its documented setup? npm run format:write npm run format:check