Skip to content
Latchkey

Running Prettier in CI: A Reference Setup

A Prettier CI gate is one step that runs prettier --check . and fails the job on exit code 1.

This page ties the others together: the minimal, reliable way to enforce formatting in a pipeline without flaky failures.

What it does

A Prettier CI gate installs the pinned Prettier version, then runs prettier --check . against the repo. Exit 0 means everything is formatted and the job passes; exit 1 means at least one file differs and the job fails with "Code style issues found". It never writes files, so the checkout stays clean.

Common usage

GitHub Actions
# .github/workflows/format.yml
- uses: actions/setup-node@v4
  with: { node-version: 20, cache: npm }
- run: npm ci
- run: npx prettier --check .

Options

StepWhat it does
npm ciInstall the exact locked Prettier version
npx prettier --check .Gate: exit 1 if any file is unformatted
--cacheSpeed up warm runs (key cache on version)
--log-level warnReduce per-file noise in the log
--no-error-on-unmatched-patternTolerate empty globs in some workspaces

In CI

Pin the Prettier version and run npm ci so local and CI agree. Make the format check its own job or step so a failure is obvious and quick to fix with prettier --write . locally. Add --cache with a version-aware cache key for speed, and quote globs so the shell does not pre-expand them.

Common errors in CI

The expected failure is "[warn] Code style issues found in the above file(s). Run Prettier with --write to fix." and exit 1; tell contributors to run prettier --write . and recommit. "No matching files. Patterns: ..." exits 2 from an empty glob. A pass locally but failure in CI almost always means a version mismatch; pin it. Line-ending only diffs mean an endOfLine or .gitattributes issue.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →