Skip to content
Latchkey

prettier --check: Gate CI on Formatting

prettier --check verifies that files already match Prettier output and exits 1 if any do not.

This is the flag CI uses. It never writes files, so it is safe to run on a checkout, and its exit code is what gates a pull request.

What it does

prettier --check formats each matched file in memory and compares it to the file on disk. It prints "Checking formatting..." then lists every file that would change. It exits 0 when all files are already formatted and 1 when at least one is not. It does not modify any file.

Common usage

Terminal
prettier --check .
prettier --check "src/**/*.{js,ts,jsx,tsx,css,md}"
npx prettier --check .

Flags

FlagWhat it does
--check / -cCheck formatting, do not write; exit 1 on mismatch
--write / -wRewrite files in place (mutually exclusive with --check)
--list-different / -lPrint only the names of unformatted files
--no-error-on-unmatched-patternDo not error if a glob matches nothing
--log-level <level>silent, error, warn, log, debug (default log)

In CI

Run prettier --check . as a dedicated step before tests so a format failure is obvious and fast. Pin the Prettier version (devDependency plus a lockfile) so the same input cannot pass locally and fail in CI because of a different release. Combine with --cache to skip unchanged files on warm runs.

Common errors in CI

A mismatch prints "[warn] Code style issues found in the above file(s). Run Prettier with --write to fix." and the step exits 1. "No matching files. Patterns: ..." with exit 2 means your glob matched nothing; add --no-error-on-unmatched-pattern or fix the pattern. Quote globs so the shell does not expand them before Prettier sees them.

Related guides

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