diff --git a/.sbt-java-formatter.conf b/.sbt-java-formatter.conf index 544e659226..3e3b0b7a12 100644 --- a/.sbt-java-formatter.conf +++ b/.sbt-java-formatter.conf @@ -10,7 +10,7 @@ ignored-files = [ "ProtobufProtocol.java" ] -//ignore by pacakges: +//ignore by packages: // 1. adated source code // 2. protobuf generated messages ignored-packages = [ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8181be970c..fcead0cf30 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -427,14 +427,21 @@ Preferences > Editor > Code Style > Scala, select Scalafmt as formatter and enab IntelliJ will then use the same settings and version as defined in `.scalafmt.conf` file. Then it's not needed to use `sbt scalafmtAll` when editing with IntelliJ. +PR validation includes checking that the Scala sources are formatted and will fail if they are not. + ### Java style -Java code is currently not automatically reformatted by sbt (expecting to have a plugin to do this soon). -Thus we ask Java contributions to follow these simple guidelines: +Akka uses [the sbt Java Formatter plugin](https://github.com/sbt/sbt-java-formatter) to format Java sources. -- 2 spaces -- `{` on same line as method name -- in all other aspects, follow the [Oracle Java Style Guide](http://www.oracle.com/technetwork/java/codeconvtoc-136057.html) +PR validation includes checking that the Java sources are formatted and will fail if they are not. + +### Code discipline opt out + +In addition to formatting the Akka build enforces code discipline through a set of compiler flags. While exploring ideas +the discipline may be more of a hindrance than a help so it is possible to disable it by setting the system property `akka.no.discipline` +to any non-empty string value when starting up sbt: `sbt -Dakka.no.discipline=youbet` + +PR validation includes the discipline flags and therefore may fail if the flags were disabled during development. Make sure you compile your code at least once with discipline enabled before sending a PR. ### Preferred ways to use timeouts in tests diff --git a/project/AkkaDisciplinePlugin.scala b/project/AkkaDisciplinePlugin.scala index 40edc882ab..0e90be7278 100644 --- a/project/AkkaDisciplinePlugin.scala +++ b/project/AkkaDisciplinePlugin.scala @@ -16,6 +16,9 @@ object AkkaDisciplinePlugin extends AutoPlugin with ScalafixSupport { override def requires: Plugins = JvmPlugin && ScalafixPlugin override lazy val projectSettings = disciplineSettings + // allow toggling for pocs/exploration of ideas without discpline + val enabled = !sys.props.contains("akka.no.discipline") + // We allow warnings in docs to get the 'snippets' right val nonFatalWarningsFor = Set("akka-docs") @@ -40,8 +43,7 @@ object AkkaDisciplinePlugin extends AutoPlugin with ScalafixSupport { "akka-stream-testkit", "akka-stream-tests", "akka-stream-tests-tck", - "akka-testkit", - ) + "akka-testkit") lazy val scalaFixSettings = Seq(Compile / scalacOptions += "-Yrangepos") @@ -54,40 +56,44 @@ object AkkaDisciplinePlugin extends AutoPlugin with ScalafixSupport { } lazy val disciplineSettings = - scalaFixSettings ++ - silencerSettings ++ Seq( - Compile / scalacOptions ++= ( - if (!nonFatalWarningsFor(name.value)) Seq("-Xfatal-warnings") - else Seq.empty - ), - Test / scalacOptions --= testUndicipline, - Compile / scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match { - case Some((2, 13)) => - disciplineScalacOptions -- Set( - "-Ywarn-inaccessible", - "-Ywarn-infer-any", - "-Ywarn-nullary-override", - "-Ywarn-nullary-unit", - "-Ypartial-unification", - "-Yno-adapted-args") - case Some((2, 12)) => - disciplineScalacOptions - case _ => - Nil - }).toSeq, - Compile / scalacOptions --= - (if (looseProjects.contains(name.value)) undisciplineScalacOptions.toSeq - else Seq.empty), - // Discipline is not needed for the docs compilation run (which uses - // different compiler phases from the regular run), and in particular - // '-Ywarn-unused:explicits' breaks 'sbt ++2.13.0-M5 akka-actor/doc' - // https://github.com/akka/akka/issues/26119 - Compile / doc / scalacOptions --= disciplineScalacOptions.toSeq :+ "-Xfatal-warnings", - // having discipline warnings in console is just an annoyance - Compile / console / scalacOptions --= disciplineScalacOptions.toSeq) + if (enabled) { + scalaFixSettings ++ + silencerSettings ++ Seq( + Compile / scalacOptions ++= ( + if (!nonFatalWarningsFor(name.value)) Seq("-Xfatal-warnings") + else Seq.empty + ), + Test / scalacOptions --= testUndicipline, + Compile / scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match { + case Some((2, 13)) => + disciplineScalacOptions -- Set( + "-Ywarn-inaccessible", + "-Ywarn-infer-any", + "-Ywarn-nullary-override", + "-Ywarn-nullary-unit", + "-Ypartial-unification", + "-Yno-adapted-args") + case Some((2, 12)) => + disciplineScalacOptions + case _ => + Nil + }).toSeq, + Compile / scalacOptions --= + (if (looseProjects.contains(name.value)) undisciplineScalacOptions.toSeq + else Seq.empty), + // Discipline is not needed for the docs compilation run (which uses + // different compiler phases from the regular run), and in particular + // '-Ywarn-unused:explicits' breaks 'sbt ++2.13.0-M5 akka-actor/doc' + // https://github.com/akka/akka/issues/26119 + Compile / doc / scalacOptions --= disciplineScalacOptions.toSeq :+ "-Xfatal-warnings", + // having discipline warnings in console is just an annoyance + Compile / console / scalacOptions --= disciplineScalacOptions.toSeq) + } else { + // we still need these in opt-out since the annotations are present + silencerSettings ++ Seq(Compile / scalacOptions += "-deprecation") + } - val testUndicipline = Seq( - "-Ywarn-dead-code", // '???' used in compile only specs + val testUndicipline = Seq("-Ywarn-dead-code" // '???' used in compile only specs ) /**