From 9e4886a6da5f80b0fb0ac9db08eba286dc13570a Mon Sep 17 00:00:00 2001 From: Marcos Pereira Date: Sun, 14 Jul 2019 15:19:52 -0400 Subject: [PATCH] Configure scalafmt for docs --- .scalafmt.conf | 1 + docs/build.sbt | 26 +++++++++++-------- .../main/templates/code/ScalaTemplates.scala | 21 ++++++++------- docs/project/plugins.sbt | 4 +-- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/.scalafmt.conf b/.scalafmt.conf index d720caf0..3c681f57 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,3 +1,4 @@ +# Keep in sync with docs/.scalafmt.conf align = true assumeStandardLibraryStripMargin = true danglingParentheses = true diff --git a/docs/build.sbt b/docs/build.sbt index 0a3ed71b..4517ef02 100644 --- a/docs/build.sbt +++ b/docs/build.sbt @@ -7,30 +7,34 @@ lazy val docs = project // use special snapshot play version for now resolvers ++= DefaultOptions.resolvers(snapshot = true), resolvers += Resolver.typesafeRepo("releases"), - libraryDependencies += component("play-test") % "test", + libraryDependencies += component("play-test") % "test", libraryDependencies += component("play-specs2") % "test", PlayDocsKeys.javaManualSourceDirectories := (baseDirectory.value / "manual" / "working" / "javaGuide" ** "code").get, PlayDocsKeys.scalaManualSourceDirectories := (baseDirectory.value / "manual" / "working" / "scalaGuide" ** "code").get, headerLicense := { val currentYear = java.time.Year.now(java.time.Clock.systemUTC).getValue - Some(HeaderLicense.Custom( - s"Copyright (C) 2009-$currentYear Lightbend Inc. " - )) + Some( + HeaderLicense.Custom( + s"Copyright (C) 2009-$currentYear Lightbend Inc. " + ) + ) }, headerEmptyLine := false - ).settings(overrideTwirlSettings: _*) + ) + .settings(overrideTwirlSettings: _*) .dependsOn(twirlApi) // The changes in Twirl imports cause a problem with the PlayDocsPlugin, which defines its own twirl compile tasks // and doesn't use the default imports provided by Twirl but defines its own by scratch, and since the defaults // have changed, this breaks. So, first we need to set all source generators in test to Nil, then we can redefine the // twirl settings. -def overrideTwirlSettings: Seq[Setting[_]] = Seq( - sourceGenerators in Test := Nil -) ++ inConfig(Test)(SbtTwirl.twirlSettings) ++ SbtTwirl.defaultSettings ++ SbtTwirl.positionSettings ++ Seq( - sourceDirectories in (Test, TwirlKeys.compileTemplates) ++= - (PlayDocsKeys.javaManualSourceDirectories.value ++ PlayDocsKeys.scalaManualSourceDirectories.value) -) +def overrideTwirlSettings: Seq[Setting[_]] = + Seq( + sourceGenerators in Test := Nil + ) ++ inConfig(Test)(SbtTwirl.twirlSettings) ++ SbtTwirl.defaultSettings ++ SbtTwirl.positionSettings ++ Seq( + sourceDirectories in (Test, TwirlKeys.compileTemplates) ++= + (PlayDocsKeys.javaManualSourceDirectories.value ++ PlayDocsKeys.scalaManualSourceDirectories.value) + ) // the twirl plugin automatically adds this dependency, but this overrides it so // it can be an interproject dependency, rather than requiring it to be published diff --git a/docs/manual/working/scalaGuide/main/templates/code/ScalaTemplates.scala b/docs/manual/working/scalaGuide/main/templates/code/ScalaTemplates.scala index 3289a976..d8953422 100644 --- a/docs/manual/working/scalaGuide/main/templates/code/ScalaTemplates.scala +++ b/docs/manual/working/scalaGuide/main/templates/code/ScalaTemplates.scala @@ -33,8 +33,7 @@ package html.utils { object ScalaTemplatesSpec extends Specification { val customer = Customer("mr customer") - val orders = List(Order("foo"), Order("bar")) - + val orders = List(Order("foo"), Order("bar")) "Scala templates" should { "support an example template" in { @@ -57,7 +56,7 @@ object ScalaTemplatesSpec extends Specification { import play.twirl.api.StringInterpolation val name = "Martin" - val p = html"

Hello $name

" + val p = html"

Hello $name

" //#string-interpolation p.body must_== "

Hello Martin

" @@ -100,13 +99,17 @@ object ScalaTemplatesSpec extends Specification { "allow comments on the first line" in { val body = html.firstLineComment("blah").body body must contain("blah") - body must not contain("Home page") + body must not contain ("Home page") } { val body = html.snippets(Seq(Product("p1", "1"), Product("p2", "2")), User("John", "Doe"), Article("")).body def segment(name: String) = { - body.linesIterator.dropWhile(_ != "").drop(1).takeWhile(_ != "").mkString("\n") + body.linesIterator + .dropWhile(_ != "") + .drop(1) + .takeWhile(_ != "") + .mkString("\n") } "allow escaping the @ character" in { @@ -140,7 +143,7 @@ object ScalaTemplatesSpec extends Specification { } "allow comments" in { - body must not contain("This is a comment") + body must not contain ("This is a comment") } "allow intering raw HTML" in { @@ -153,10 +156,10 @@ object ScalaTemplatesSpec extends Specification { body must contain("User(Foo,Bar)") body must contain("value inside option") - body must not contain("Option(value inside option)") + body must not contain ("Option(value inside option)") body must contain("firstlast") - body must not contain("List") + body must not contain ("List") body must contain("helloUser(Foo,Bar)value inside optionfirstlast") } } -} \ No newline at end of file +} diff --git a/docs/project/plugins.sbt b/docs/project/plugins.sbt index 870c912c..0d9c95ed 100644 --- a/docs/project/plugins.sbt +++ b/docs/project/plugins.sbt @@ -5,5 +5,5 @@ lazy val sbtTwirl = ProjectRef(Path.fileProperty("user.dir").getParentFile, "plu resolvers ++= DefaultOptions.resolvers(snapshot = true) addSbtPlugin("com.typesafe.play" % "play-docs-sbt-plugin" % sys.props.getOrElse("play.version", "2.8.0-M3")) - -addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.2.0") \ No newline at end of file +addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.2.0") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.0.0")