Default (and sane) configurations for Scalafmt

Installation

Add the following line to your plugins.sbt file:

addSbtPlugin("com.alejandrohdezma" % "sbt-scalafmt-defaults" % "0.4.0")

You'll also need to provide the sbt-scalafmt plugin.

Usage

The included plugin is automatically activated. It will enable scalafmtOnCompile by default and will create a .scalafmt.conf in your project's root folder with the following content:

# This file has been automatically generated and should
# not be edited nor added to source control systems.

# To edit the original configurations go to
# https://github.com/alejandrohdezma/sbt-scalafmt-defaults/edit/master/.scalafmt.conf

version = 2.7.3

maxColumn = 120

newlines {
  alwaysBeforeTopLevelStatements = true
  sometimesBeforeColonInMethodReturnType = false
}

style = defaultWithAlign

align {
  tokens.add = [
    {
      code = ":=", owner = "Term.ApplyInfix"
    },
    {
      code = "+=", owner = "Term.ApplyInfix"
    },
    {
      code = "++=", owner = "Term.ApplyInfix"
    },
    {
      code = "--=", owner = "Term.ApplyInfix"
    },
    {
      code = "-=", owner = "Term.ApplyInfix"
    }
  ]
}

binPack {
  literalArgumentLists = true
  literalsExclude = [ "Term.Name" ]
}

docstrings = JavaDoc

rewrite {
  rules = [
    ExpandImportSelectors,
    PreferCurlyFors
    RedundantBraces,
    RedundantParens,
    SortModifiers
  ]
  redundantBraces.maxLines = 1
  redundantBraces.stringInterpolation = true
}

includeCurlyBraceInSelectChains = false

includeNoParensInSelectChains = false

optIn.blankLineBeforeDocstring = true

You can add the .scalafmt.conf file to the repository's .gitignore, since it's going to be automatically re-created on every build.

Extra configurations

Extra configurations can be added to a file named .scalafmt-extra.conf at the root of your repository. The content of this file will be automatically appended to the auto-generated .scalafmt.conf.