.pre-commit-config.yaml.
repos:
- repo: local
hooks:
- id: scalafmt
name: scalafmt
entry: bash -c 'scala-cli fmt -- "$@" && git add "$@"' --
language: system
files: '\.(scala|sbt)$'
stages: [pre-commit]This runs [scala-cli fmt](https://scala-cli.virtuslab.org/docs/commands/fmt/) when .scala or .sbt files are staged, then re-stages only those files. Works reliably with renames and deletions.
The hooks below are still functional but no longer maintained.
-
sbt-fatal-warnings- turns on-Xfatal-warnings, runs a clean compilation on the given scope. -
sbt-unused-imports- as above, but also adds the "unused imports" warning. -
scalafmt-check- runsscalafmt --mode=changed --test. -
scalafmt-autofix- runsscalafmt --mode=changedand automatically stages the reformatted files.
Known issue: --mode=changed fails when staged files include renames (git mv).