Skip to content
Latchkey

How to Run rustfmt and clippy in GitHub Actions

Rust catches a lot at compile time, but rustfmt and clippy catch the style and correctness smells the compiler allows.

Run cargo fmt --check and cargo clippy -- -D warnings so any formatting drift or lint warning fails the job.

Steps

  • Install the rustfmt and clippy components with the toolchain.
  • Run cargo fmt --all -- --check to verify formatting.
  • Run cargo clippy --all-targets -- -D warnings so warnings become errors.

Workflow

.github/workflows/rust-lint.yml
name: Rust Lint
on: [pull_request]
jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy
      - run: cargo fmt --all -- --check
      - run: cargo clippy --all-targets --all-features -- -D warnings

Notes

  • Cache the cargo registry and target dir to keep clippy runs fast.
  • On Latchkey managed runners Rust lint jobs run cheaper and self-heal if a runner drops.

Related guides

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