Skip to content
Latchkey

How to Run a Prettier Format Check in GitHub Actions

Formatting debates waste reviews; prettier --check makes the formatter the arbiter and fails the build when code drifts.

Run prettier --check . so unformatted files exit non-zero, turning the PR check red until the author runs prettier --write.

Steps

  • Install dependencies with npm ci.
  • Run prettier --check . against the repository (respecting .prettierignore).
  • Let the non-zero exit fail the job so unformatted code is blocked.

Workflow

.github/workflows/prettier.yml
name: Prettier
on: [pull_request]
jobs:
  prettier:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: npm
      - run: npm ci
      - run: npx prettier --check .

Notes

  • Keep a .prettierignore so generated files do not trip the check.
  • On Latchkey managed runners format checks run cheaper and self-heal if a runner drops.

Related guides

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