Skip to content
Latchkey

sbt scalafmt "must be formatted" check failure in CI

The CI step ran scalafmtCheckAll (or scalafmtCheck), which fails if any file is not already formatted to the .scalafmt.conf rules. It does not rewrite files; it only reports the ones that differ.

What this error means

A formatting gate fails with "X.scala must be formatted" or "Some files are not formatted properly" and lists the offending files.

scalafmt
[error] /src/main/scala/App.scala isn't formatted properly!
[error] --- a/App.scala
[error] +++ b/App.scala (formatted)
[error] (Compile / scalafmtCheck) scalafmt: 1 files must be formatted

Common causes

Code was committed without running scalafmt

The file differs from the formatted output because it was not run through scalafmtAll before committing.

A scalafmt version or config mismatch

A different version in .scalafmt.conf locally versus CI produces different formatting, so the check flags files that look formatted locally.

How to fix it

Format the files and commit

  1. Run sbt scalafmtAll (and scalafmtSbt) to rewrite files.
  2. Commit the reformatted files.
  3. Re-run CI so scalafmtCheckAll passes.
Terminal
sbt scalafmtAll scalafmtSbt

Pin the scalafmt version in config

Set an explicit version in .scalafmt.conf so local and CI formatting are byte-identical.

.scalafmt.conf
# .scalafmt.conf
version = "3.8.1"
runner.dialect = scala213

How to prevent it

  • Run scalafmtAll locally or in a pre-commit hook before pushing.
  • Pin the scalafmt version in .scalafmt.conf so formatting is deterministic.
  • Keep the same scalafmt config across all contributors.

Related guides

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