Skip to content
Latchkey

ktlint "not formatted" / lint errors failing CI

ktlint enforces a Kotlin code style. The ktlintCheck task fails when a file is "not formatted" or violates a rule. It reports each file, line, and rule id, and refuses to pass CI until the code matches the configured style.

What this error means

The ktlintCheck (or ktlintMainSourceSetCheck) task fails with lines like "Main.kt:12:1: Unexpected indentation (standard:indent)" or a summary that files are not formatted.

ktlint
> Task :app:ktlintMainSourceSetCheck FAILED
/app/src/main/kotlin/Main.kt:12:1: Unexpected indentation (4) (should be 8) (standard:indent)
/app/src/main/kotlin/Main.kt:20:80: Exceeded max line length (standard:max-line-length)

Common causes

Code was not run through the formatter

Files were committed without applying ktlint formatting, so the check finds style violations.

A ktlint or editorconfig rule changed

Upgrading ktlint or changing .editorconfig altered the expected style, so previously passing code now fails.

How to fix it

Auto-format then commit

  1. Run the ktlint format task to fix violations automatically.
  2. Review and commit the formatting changes.
  3. Re-run ktlintCheck to confirm a clean pass.
Terminal
./gradlew ktlintFormat
./gradlew ktlintCheck

Pin the ktlint version and editorconfig

Keep the ktlint version and .editorconfig consistent so local formatting matches CI exactly.

.editorconfig
# .editorconfig
[*.{kt,kts}]
max_line_length = 120

How to prevent it

  • Run ktlintFormat in a pre-commit or pre-push hook.
  • Pin the ktlint plugin version so CI and local styles match.
  • Keep .editorconfig committed and consistent across the team.

Frequently asked questions

What causes ""ktlint ... not formatted""?
Files were committed without applying ktlint formatting, so the check finds style violations.
How do I fix "ktlint ... not formatted"?
Auto-format then commit

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card