Switch to Scalafmt in build
* AvoidInfix in scalafmt.conf * align.tokens in scalafmt.conf * scalafmt in MultiJvm * sbt-scalafmt 2.0.0-RC5 * scalafmt in all* command alias * scalafmtAll in CONTRIBUTING.md
This commit is contained in:
parent
18710d3aba
commit
e4d38f92a4
7 changed files with 66 additions and 38 deletions
48
.scalafmt.conf
Normal file
48
.scalafmt.conf
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
version = 2.0.0-RC5
|
||||||
|
|
||||||
|
style = defaultWithAlign
|
||||||
|
|
||||||
|
danglingParentheses = true
|
||||||
|
docstrings = JavaDoc
|
||||||
|
indentOperator = spray
|
||||||
|
maxColumn = 120
|
||||||
|
rewrite.rules = [RedundantParens, SortImports, AvoidInfix]
|
||||||
|
unindentTopLevelOperators = true
|
||||||
|
align.tokens = [{code = "=>", owner = "Case"}]
|
||||||
|
align.openParenDefnSite = true
|
||||||
|
align.openParenCallSite = true
|
||||||
|
optIn.breakChainOnFirstMethodDot = false
|
||||||
|
optIn.configStyleArguments = false
|
||||||
|
danglingParentheses = false
|
||||||
|
spaces.inImportCurlyBraces = true
|
||||||
|
rewrite.neverInfix.excludeFilters = [
|
||||||
|
and
|
||||||
|
min
|
||||||
|
max
|
||||||
|
until
|
||||||
|
to
|
||||||
|
by
|
||||||
|
eq
|
||||||
|
ne
|
||||||
|
"should.*"
|
||||||
|
"contain.*"
|
||||||
|
"must.*"
|
||||||
|
in
|
||||||
|
ignore
|
||||||
|
be
|
||||||
|
taggedAs
|
||||||
|
thrownBy
|
||||||
|
synchronized
|
||||||
|
have
|
||||||
|
when
|
||||||
|
size
|
||||||
|
only
|
||||||
|
noneOf
|
||||||
|
oneElementOf
|
||||||
|
noElementsOf
|
||||||
|
atLeastOneElementOf
|
||||||
|
atMostOneElementOf
|
||||||
|
allElementsOf
|
||||||
|
inOrderElementsOf
|
||||||
|
theSameElementsAs
|
||||||
|
]
|
||||||
|
|
@ -147,6 +147,13 @@ project akka-cluster
|
||||||
multi-jvm:testOnly akka.cluster.SunnyWeather
|
multi-jvm:testOnly akka.cluster.SunnyWeather
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To format the Scala source code:
|
||||||
|
```
|
||||||
|
sbt
|
||||||
|
akka-cluster/scalafmtAll
|
||||||
|
akka-persistence/scalafmtAll
|
||||||
|
```
|
||||||
|
|
||||||
### Do not use `-optimize` Scala compiler flag
|
### Do not use `-optimize` Scala compiler flag
|
||||||
|
|
||||||
Akka has not been compiled or tested with `-optimize` Scala compiler flag. (In sbt, you can specify compiler options in the `scalacOptions` key.)
|
Akka has not been compiled or tested with `-optimize` Scala compiler flag. (In sbt, you can specify compiler options in the `scalacOptions` key.)
|
||||||
|
|
@ -360,7 +367,10 @@ In such situations we prefer 'internal' over 'impl' as a package name.
|
||||||
|
|
||||||
### Scala style
|
### Scala style
|
||||||
|
|
||||||
Akka uses [Scalariform](https://github.com/daniel-trinh/scalariform) to enforce some of the code style rules.
|
Akka uses [Scalafmt](https://scalameta.org/scalafmt/docs/installation.html) to enforce some of the code style rules.
|
||||||
|
|
||||||
|
When IntelliJ detects the `.scalafmt.conf` and promts "Scalafmt configuration detected in this project" you should
|
||||||
|
select "Continue using IntelliJ formatter" and instead install the [Scalafmt IntelliJ plugin](https://scalameta.org/scalafmt/docs/installation.html#intellij). Install the nightly plugin (until version 2.0.0 or later becomes stable) and enable "Format on save".
|
||||||
|
|
||||||
### Java style
|
### Java style
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -524,7 +524,6 @@ def akkaModule(name: String): Project =
|
||||||
Project(id = name, base = file(name))
|
Project(id = name, base = file(name))
|
||||||
.settings(akka.AkkaBuild.buildSettings)
|
.settings(akka.AkkaBuild.buildSettings)
|
||||||
.settings(akka.AkkaBuild.defaultSettings)
|
.settings(akka.AkkaBuild.defaultSettings)
|
||||||
.settings(akka.Formatting.formatSettings)
|
|
||||||
.enablePlugins(BootstrapGenjavadoc)
|
.enablePlugins(BootstrapGenjavadoc)
|
||||||
|
|
||||||
/* Command aliases one can run locally against a module
|
/* Command aliases one can run locally against a module
|
||||||
|
|
@ -534,7 +533,8 @@ def akkaModule(name: String): Project =
|
||||||
def commandValue(p: Project, externalTest: Option[Project] = None) = {
|
def commandValue(p: Project, externalTest: Option[Project] = None) = {
|
||||||
val test = externalTest.getOrElse(p)
|
val test = externalTest.getOrElse(p)
|
||||||
val optionalMima = if (p.id.endsWith("-typed")) "" else s";${p.id}/mimaReportBinaryIssues"
|
val optionalMima = if (p.id.endsWith("-typed")) "" else s";${p.id}/mimaReportBinaryIssues"
|
||||||
s";${test.id}/test:compile$optionalMima;${docs.id}/paradox"
|
val optionalExternalTestFormat = externalTest.map(t => s";${t.id}/scalafmtAll").getOrElse("")
|
||||||
|
s";${p.id}/scalafmtAll$optionalExternalTestFormat;${test.id}/test:compile$optionalMima;${docs.id}/paradox"
|
||||||
}
|
}
|
||||||
addCommandAlias("allActor", commandValue(actor, Some(actorTests)))
|
addCommandAlias("allActor", commandValue(actor, Some(actorTests)))
|
||||||
addCommandAlias("allRemote", commandValue(remote, Some(remoteTests)))
|
addCommandAlias("allRemote", commandValue(remote, Some(remoteTests)))
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import java.util.Properties
|
||||||
|
|
||||||
import sbt.Keys._
|
import sbt.Keys._
|
||||||
import sbt._
|
import sbt._
|
||||||
|
import org.scalafmt.sbt.ScalafmtPlugin.autoImport._
|
||||||
|
|
||||||
import scala.collection.breakOut
|
import scala.collection.breakOut
|
||||||
|
|
||||||
|
|
@ -25,7 +26,6 @@ object AkkaBuild {
|
||||||
|
|
||||||
lazy val rootSettings = Release.settings ++
|
lazy val rootSettings = Release.settings ++
|
||||||
UnidocRoot.akkaSettings ++
|
UnidocRoot.akkaSettings ++
|
||||||
Formatting.formatSettings ++
|
|
||||||
Protobuf.settings ++ Seq(
|
Protobuf.settings ++ Seq(
|
||||||
parallelExecution in GlobalScope := System.getProperty("akka.parallelExecution", parallelExecutionByDefault.toString).toBoolean,
|
parallelExecution in GlobalScope := System.getProperty("akka.parallelExecution", parallelExecutionByDefault.toString).toBoolean,
|
||||||
version in ThisBuild := "2.5-SNAPSHOT"
|
version in ThisBuild := "2.5-SNAPSHOT"
|
||||||
|
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016-2019 Lightbend Inc. <https://www.lightbend.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
package akka
|
|
||||||
|
|
||||||
import com.typesafe.sbt.SbtMultiJvm.MultiJvmKeys.MultiJvm
|
|
||||||
import com.typesafe.sbt.SbtScalariform.ScalariformKeys
|
|
||||||
import sbt._
|
|
||||||
|
|
||||||
object Formatting {
|
|
||||||
import scalariform.formatter.preferences._
|
|
||||||
|
|
||||||
lazy val formatSettings = Seq(
|
|
||||||
ScalariformKeys.preferences := setPreferences(ScalariformKeys.preferences.value),
|
|
||||||
ScalariformKeys.preferences in Compile := setPreferences(ScalariformKeys.preferences.value),
|
|
||||||
ScalariformKeys.preferences in Test := setPreferences(ScalariformKeys.preferences.value),
|
|
||||||
ScalariformKeys.preferences in MultiJvm := setPreferences(ScalariformKeys.preferences.value)
|
|
||||||
)
|
|
||||||
|
|
||||||
def setPreferences(preferences: IFormattingPreferences) = preferences
|
|
||||||
.setPreference(RewriteArrowSymbols, true)
|
|
||||||
.setPreference(AlignParameters, true)
|
|
||||||
.setPreference(AlignSingleLineCaseStatements, true)
|
|
||||||
.setPreference(DoubleIndentConstructorArguments, false)
|
|
||||||
.setPreference(DoubleIndentMethodDeclaration, false)
|
|
||||||
.setPreference(DanglingCloseParenthesis, Preserve)
|
|
||||||
.setPreference(NewlineAtEndOfFile, true)
|
|
||||||
}
|
|
||||||
|
|
@ -6,12 +6,12 @@ package akka
|
||||||
|
|
||||||
import akka.TestExtras.Filter.Keys._
|
import akka.TestExtras.Filter.Keys._
|
||||||
import com.typesafe.sbt.MultiJvmPlugin.MultiJvmKeys.multiJvmCreateLogger
|
import com.typesafe.sbt.MultiJvmPlugin.MultiJvmKeys.multiJvmCreateLogger
|
||||||
import com.typesafe.sbt.{SbtMultiJvm, SbtScalariform}
|
import com.typesafe.sbt.SbtMultiJvm
|
||||||
import com.typesafe.sbt.SbtMultiJvm.MultiJvmKeys._
|
import com.typesafe.sbt.SbtMultiJvm.MultiJvmKeys._
|
||||||
import com.typesafe.sbt.SbtScalariform.ScalariformKeys
|
|
||||||
import sbt.{ Def, _ }
|
import sbt.{ Def, _ }
|
||||||
import sbt.Keys._
|
import sbt.Keys._
|
||||||
import de.heikoseeberger.sbtheader.HeaderPlugin.autoImport._
|
import de.heikoseeberger.sbtheader.HeaderPlugin.autoImport._
|
||||||
|
import org.scalafmt.sbt.ScalafmtPlugin.scalafmtConfigSettings
|
||||||
|
|
||||||
object MultiNode extends AutoPlugin {
|
object MultiNode extends AutoPlugin {
|
||||||
|
|
||||||
|
|
@ -57,10 +57,9 @@ object MultiNode extends AutoPlugin {
|
||||||
|
|
||||||
private val multiJvmSettings =
|
private val multiJvmSettings =
|
||||||
SbtMultiJvm.multiJvmSettings ++
|
SbtMultiJvm.multiJvmSettings ++
|
||||||
inConfig(MultiJvm)(SbtScalariform.configScalariformSettings) ++
|
inConfig(MultiJvm)(scalafmtConfigSettings) ++
|
||||||
Seq(
|
Seq(
|
||||||
jvmOptions in MultiJvm := defaultMultiJvmOptions,
|
jvmOptions in MultiJvm := defaultMultiJvmOptions,
|
||||||
compileInputs in (MultiJvm, compile) := ((compileInputs in (MultiJvm, compile)) dependsOn (ScalariformKeys.format in MultiJvm)).value,
|
|
||||||
scalacOptions in MultiJvm := (scalacOptions in Test).value,
|
scalacOptions in MultiJvm := (scalacOptions in Test).value,
|
||||||
logLevel in multiJvmCreateLogger := Level.Debug, // to see ssh establishment
|
logLevel in multiJvmCreateLogger := Level.Debug, // to see ssh establishment
|
||||||
multiJvmCreateLogger in MultiJvm := { // to use normal sbt logging infra instead of custom sbt-multijvm-one
|
multiJvmCreateLogger in MultiJvm := { // to use normal sbt logging infra instead of custom sbt-multijvm-one
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ addSbtPlugin("com.typesafe.sbt" % "sbt-multi-jvm" % "0.4.0")
|
||||||
//#sbt-multi-jvm
|
//#sbt-multi-jvm
|
||||||
|
|
||||||
addSbtPlugin("com.lightbend.sbt" % "sbt-java-formatter" % "0.4.1")
|
addSbtPlugin("com.lightbend.sbt" % "sbt-java-formatter" % "0.4.1")
|
||||||
addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.2")
|
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.0.0-RC5")
|
||||||
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.1")
|
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.1")
|
||||||
addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.4")
|
addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.4")
|
||||||
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.3.0")
|
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.3.0")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue