The sbt plugin
The plugin requires sbt 2, and runs against Scala 3 code.
// project/plugins.sbt
addSbtPlugin("com.colofabrix.scala" % "sbt-dixtra" % "$VERSION")
Tasks
| Task | What it does |
|---|---|
dixtraFormat |
Formats the sources of a configuration (Compile; Test / dixtraFormat for the tests) |
dixtraCheck |
Fails when a source of a configuration is not formatted |
dixtraFormatAll |
Formats the sources of Compile and Test, and the build files |
dixtraCheckAll |
Fails when a source of Compile or Test, or a build file, is not formatted |
dixtraFormatSbt |
Formats the build: the .sbt files, and the .sbt / .scala files in project/ |
dixtraCheckSbt |
Fails when a file of the build is not formatted |
dixtraFormatOnly <files> |
Formats the given files, relative to the project directory |
dixtraClasspath |
The jars of dixtra-cli and its dependencies, as resolved for dixtraVersion |
The tasks cover the unmanaged source directories of a configuration, so the generated sources are left alone.
Settings
| Setting | Default | What it does |
|---|---|---|
dixtraVersion |
the plugin version | The version of Dixtra to format with |
dixtraConfig |
None |
A configuration file, instead of the nearest .dixtra.conf |
dixtraChangedSince |
None |
A git ref: format or check only the files changed since it |
dixtraOnCompile |
false |
Format the sources of a configuration before compiling them |
// build.sbt
dixtraOnCompile := true
dixtraChangedSince := Some("origin/main")
In a CI job
The check tasks fail the build when a file is not formatted, which is what a CI job wants:
sbt dixtraCheckAll
Only the files that changed
Formatting a whole project on every save is wasteful when only a few files changed. Both the plugin and the command line can restrict the work to the files that changed since a git ref:
// build.sbt
dixtraChangedSince := Some("origin/main")
dixtra --changed-since origin/main src
A file counts as changed when it was committed since the ref, has uncommitted changes, or is new and not ignored by git. With HEAD, only the uncommitted changes count.