Configuration

Dixtra gets its configuration from .dixtra.conf files, written in HOCON, the format of the reference configuration of the command line.

config-version = 1.0.0

max-column = 100

braces { style = stroustrup, if = force-braces }
paths.excluded = ["**/generated/**"]

A project overrides only the settings it changes. Every setting that is not written keeps its default, listed with an example for every value in the settings reference.

Which file applies

For each file it formats, Dixtra uses the nearest .dixtra.conf in the directory of the file, or in a directory above it. Without one, it uses the defaults.

The lookup stops at the first configuration found: a .dixtra.conf in a subdirectory does not inherit the one of the directory above it. Put the settings that apply to a whole project in the configuration of its root, and the ones that apply to a subtree in the configuration of that subtree.

Replacing the configuration

A file given with --config-path, or text given with --config-string, replaces the lookup: no .dixtra.conf is read at all.

dixtra --config-string "max-column = 80, braces.style = allman" src
dixtra --config-path build/.dixtra.conf src

The same options exist in the sbt plugin, as dixtraConfig.

The top-level settings

Setting Default What it does
config-version 1.0.0 The version of the schema of the configuration. A configuration without it is read as the current version; one written for a later version, or for another major version, is rejected instead of being half understood
max-column 120 The longest a line can be. A construct whose one-line form does not fit within this width breaks
compat213 false Whether the output must also be valid Scala 2.13, for the sources of a project cross-compiled for Scala 2.13 and Scala 3

Configuration version

Dixtra follows Semantic versioning where given a version number MAJOR.MINOR.PATCH the:

A configuration written for a another minor or path version of the same major version is guaranteed to be backward compatible.

Column width

This settings ensure that no line will exceed this width.

Scala 2.13 compatibility

compat213 keeps the output valid Scala 2.13 too, for the sources of a project cross-compiled for Scala 2.13 and Scala 3. When it is true, Dixtra enforces the settings that would otherwise write Scala 3 syntax, whatever the rest of the configuration says:

Setting Value
braces.<construct> keep, except package and try: force-braces
braces.single-expr.<construct> keep
body.semicolon-statements keep

braces.style, braces.imports and the other body settings keep their values. A source that is valid Scala 2.13 too keeps the braces of the Scala 2 form, and a package clause and a try written without braces get them:

def f = {
  a()
  b()
}

A source that is valid only in Scala 3 is still formatted, but the setting does not make it valid Scala 2.13. A source that is Scala 2 is still rejected. The setting can be set in a path-overrides entry, so only some files are formatted in compatibility mode.

The settings reference

The settings are split into one page per group. Each page lists the settings, their defaults and an example for every value they take.

Group What it holds
braces The braces, the end markers or the indentation of every construct, and where the braces go
body Whether a body stays on the line of its separator, or goes below it
selector-chain When a chain of selections breaks, and how
alignment What lines up in columns
blank-lines The blank lines at the edges of the bodies, between groups and before the scaladocs
call-site The arguments of a call and the elements of a tuple: groups and commas
definition-site The parameters of a def or of a class, and the selectors of an import: groups and commas
overflow What happens to what goes past max-column
housekeeping The trailing whitespace, the line break at the end of the file, the line endings
paths The files of a directory to format
path-overrides Other settings for some of the files

Settings for some files

path-overrides gives some files other settings. Each key is a glob, with the syntax of paths (*, **, ?), and its section holds the settings of the files it matches:

path-overrides {
  "src/main/scala/legacy/**" { trailing-commas = never }
  "build.sbt" { housekeeping.enforce-eof = false }
}

The details of the globs are in path overrides.

Ignoring the formatting

The code between a dixtra: off comment and a dixtra: on comment stays exactly as written:

object Matrices {
  val a = 1

  // dixtra: off
  val identity = Array(
    1, 0,
    0, 1,
  )
  // dixtra: on
}

Disabling Dixtra for a subproject

The dixtra: off markers protect regions of one file. To leave the sources and build files of a whole sbt subproject as written, turn the plugin off for that subproject:

lazy val myProject = 
  project
    .in(file("myProject"))
    .disablePlugins(DixtraPlugin)

The plugin then adds nothing to the subproject: its sources are not formatted on compile, and none of the dixtraFormat* or dixtraCheck* tasks run for it.