SC

Scalafmt + Scalafix

Scalafmt for code formatting and Scalafix for linting and automated refactoring in Scala projects

Details

Language / Topic
scalaScala
Category
Linter / Formatter

Rules

balanced
- Configure `scalafmt` via `.scalafmt.conf` at the project root — set `version`, `maxColumn`, and `align.preset` to enforce consistent formatting.
- Run `sbt scalafmtCheck` and `sbt scalafix` in CI to fail the build on formatting or lint violations.
- Use `scalafix` rules `OrganizeImports` and `RemoveUnused` to automatically clean up unused imports on every save.
- Pin the `scalafmt` version in `.scalafmt.conf` with `version = "3.x.y"` to guarantee reproducible formatting across developer machines.
- Enable `rewrite.rules = [SortImports, RedundantBraces, PreferCurlyFors]` in `.scalafmt.conf` to auto-fix common style issues.
- Add `scalafix` to `project/plugins.sbt` and configure rules in `.scalafix.conf` — use `DisableSyntax` to forbid `null`, `return`, and `var` where inappropriate.
- Configure `wartremover` alongside Scalafix for compile-time warnings on unsafe patterns like `Any`, `AsInstanceOf`, and `ToString`.