Formatting in CI/CD Pipelines
You'll learn how to automatically verify code formatting in your continuous integration pipeline so unformatted code never reaches production.
Why Check Formatting in CI?
You've already learned to use Prettier locally with pre-commit hooks, but what happens when someone bypasses those hooks or pushes directly? Your CI/CD pipeline is the last line of defense — think of it as the quality gate that every piece of code must pass through before merging.
By adding Prettier checks to CI, you ensure that all code in your repository stays consistently formatted, regardless of individual developer workflows.
How It Works
Instead of running Prettier with automatic fixing (--write), CI runs Prettier in check mode (--check). This verifies formatting without modifying files. If any file doesn't match Prettier's expected output, the CI job fails and the pull request cannot merge.
The Concept in Practice
In your CI configuration (GitHub Actions, GitLab CI, CircleCI, etc.), you add a step that:
- Installs your dependencies (including Prettier)
- Runs
prettier --check .to verify all files - Fails the build if formatting issues exist
This creates accountability: developers see the CI failure, know exactly which files need formatting, and run Prettier locally before pushing again.
Integration Benefits
Unlike pre-commit hooks (which can be skipped), CI checks are mandatory gatekeepers. They catch formatting drift, enforce team standards across all contributors, and maintain consistency even when onboarding new developers who haven't configured their local tooling yet.
Key Takeaway: Adding Prettier to CI/CD pipelines (prettier --check) ensures formatting standards are enforced automatically, catching unformatted code before it reaches your main branch and maintaining consistent code quality across your entire team.