Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to the latest scalafmt 2.0.0-RC7 / sbt-scalafmt 2.0.0 #1731

Merged
merged 5 commits into from
May 28, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
version = 1.4.0
version = 2.0.0-RC7

style = defaultWithAlign

align.tokens = [off]
align.openParenDefnSite = true
align.openParenCallSite = true
danglingParentheses = true
docstrings = JavaDoc
indentOperator = spray
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ script:
jobs:
include:
- stage: check
script: sbt scalafmtCheck || { echo "[error] Unformatted code found. Please run 'Test/compile' and commit the reformatted code."; false; }
script: sbt scalafmtCheckAll || { echo "[error] Unformatted code found. Please run 'Test/compile' and commit the reformatted code."; false; }
name: "Code style check (fixed with `sbt Test/compile`)"
- script: sbt scalafmtSbtCheck || { echo "[error] Unformatted sbt code found. Please run 'scalafmtSbt' and commit the reformatted code."; false; }
name: "Build code style check (fixed with `sbt scalafmtSbt`)"
Expand Down
88 changes: 44 additions & 44 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -279,49 +279,49 @@ lazy val docs = project
Preprocess / siteSubdirName := s"api/alpakka/${if (isSnapshot.value) "snapshot" else version.value}",
Preprocess / sourceDirectory := (LocalRootProject / ScalaUnidoc / unidoc / target).value,
Preprocess / preprocessRules := Seq(
("\\.java\\.scala".r, _ => ".java")
),
("\\.java\\.scala".r, _ => ".java")
),
Paradox / siteSubdirName := s"docs/alpakka/${if (isSnapshot.value) "snapshot" else version.value}",
paradoxProperties ++= Map(
"akka.version" -> Dependencies.AkkaVersion,
"akka-http.version" -> Dependencies.AkkaHttpVersion,
"couchbase.version" -> Dependencies.CouchbaseVersion,
"hadoop.version" -> Dependencies.HadoopVersion,
"extref.akka.base_url" -> s"https://doc.akka.io/docs/akka/${Dependencies.AkkaVersion}/%s",
"scaladoc.akka.base_url" -> s"https://doc.akka.io/api/akka/${Dependencies.AkkaVersion}",
"javadoc.akka.base_url" -> s"https://doc.akka.io/japi/akka/${Dependencies.AkkaVersion}/",
"extref.akka-http.base_url" -> s"https://doc.akka.io/docs/akka-http/${Dependencies.AkkaHttpVersion}/%s",
"scaladoc.akka.http.base_url" -> s"https://doc.akka.io/api/akka-http/${Dependencies.AkkaHttpVersion}/",
"javadoc.akka.http.base_url" -> s"https://doc.akka.io/japi/akka-http/${Dependencies.AkkaHttpVersion}/",
"extref.couchbase.base_url" -> s"https://docs.couchbase.com/java-sdk/${Dependencies.CouchbaseVersionForDocs}/%s",
"extref.java-api.base_url" -> "https://docs.oracle.com/javase/8/docs/api/index.html?%s.html",
"extref.geode.base_url" -> s"https://geode.apache.org/docs/guide/${Dependencies.GeodeVersionForDocs}/%s",
"extref.javaee-api.base_url" -> "https://docs.oracle.com/javaee/7/api/index.html?%s.html",
"extref.paho-api.base_url" -> "https://www.eclipse.org/paho/files/javadoc/index.html?%s.html",
"extref.slick.base_url" -> s"https://slick.lightbend.com/doc/${Dependencies.SlickVersion}/%s",
// Solr
"extref.solr.base_url" -> s"https://lucene.apache.org/solr/guide/${Dependencies.SolrVersionForDocs}/%s",
"javadoc.org.apache.solr.base_url" -> s"https://lucene.apache.org/solr/${Dependencies.SolrVersionForDocs}_0/solr-solrj/",
// Java
"javadoc.base_url" -> "https://docs.oracle.com/javase/8/docs/api/",
"javadoc.javax.jms.base_url" -> "https://docs.oracle.com/javaee/7/api/",
"javadoc.com.couchbase.base_url" -> s"https://docs.couchbase.com/sdk-api/couchbase-java-client-${Dependencies.CouchbaseVersion}/",
"javadoc.org.apache.kudu.base_url" -> s"https://kudu.apache.org/releases/${Dependencies.KuduVersion}/apidocs/",
"javadoc.org.apache.hadoop.base_url" -> s"https://hadoop.apache.org/docs/r${Dependencies.HadoopVersion}/api/",
"javadoc.com.amazonaws.base_url" -> "https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/",
"javadoc.software.amazon.awssdk.base_url" -> "https://sdk.amazonaws.com/java/api/latest/",
// Eclipse Paho client for MQTT
"javadoc.org.eclipse.paho.client.mqttv3.base_url" -> "https://www.eclipse.org/paho/files/javadoc/",
"javadoc.org.bson.codecs.configuration.base_url" -> "https://mongodb.github.io/mongo-java-driver/3.7/javadoc/",
"scaladoc.scala.base_url" -> s"https://www.scala-lang.org/api/${scalaBinaryVersion.value}.x/",
"scaladoc.akka.stream.alpakka.base_url" -> {
val docsHost = sys.env
.get("CI")
.map(_ => "https://doc.akka.io")
.getOrElse(s"http://localhost:${(previewSite / previewFixedPort).value.getOrElse(4000)}")
s"$docsHost/api/alpakka/${if (isSnapshot.value) "snapshot" else version.value}/"
}
),
"akka.version" -> Dependencies.AkkaVersion,
"akka-http.version" -> Dependencies.AkkaHttpVersion,
"couchbase.version" -> Dependencies.CouchbaseVersion,
"hadoop.version" -> Dependencies.HadoopVersion,
"extref.akka.base_url" -> s"https://doc.akka.io/docs/akka/${Dependencies.AkkaVersion}/%s",
"scaladoc.akka.base_url" -> s"https://doc.akka.io/api/akka/${Dependencies.AkkaVersion}",
"javadoc.akka.base_url" -> s"https://doc.akka.io/japi/akka/${Dependencies.AkkaVersion}/",
"extref.akka-http.base_url" -> s"https://doc.akka.io/docs/akka-http/${Dependencies.AkkaHttpVersion}/%s",
"scaladoc.akka.http.base_url" -> s"https://doc.akka.io/api/akka-http/${Dependencies.AkkaHttpVersion}/",
"javadoc.akka.http.base_url" -> s"https://doc.akka.io/japi/akka-http/${Dependencies.AkkaHttpVersion}/",
"extref.couchbase.base_url" -> s"https://docs.couchbase.com/java-sdk/${Dependencies.CouchbaseVersionForDocs}/%s",
"extref.java-api.base_url" -> "https://docs.oracle.com/javase/8/docs/api/index.html?%s.html",
"extref.geode.base_url" -> s"https://geode.apache.org/docs/guide/${Dependencies.GeodeVersionForDocs}/%s",
"extref.javaee-api.base_url" -> "https://docs.oracle.com/javaee/7/api/index.html?%s.html",
"extref.paho-api.base_url" -> "https://www.eclipse.org/paho/files/javadoc/index.html?%s.html",
"extref.slick.base_url" -> s"https://slick.lightbend.com/doc/${Dependencies.SlickVersion}/%s",
// Solr
"extref.solr.base_url" -> s"https://lucene.apache.org/solr/guide/${Dependencies.SolrVersionForDocs}/%s",
"javadoc.org.apache.solr.base_url" -> s"https://lucene.apache.org/solr/${Dependencies.SolrVersionForDocs}_0/solr-solrj/",
// Java
"javadoc.base_url" -> "https://docs.oracle.com/javase/8/docs/api/",
"javadoc.javax.jms.base_url" -> "https://docs.oracle.com/javaee/7/api/",
"javadoc.com.couchbase.base_url" -> s"https://docs.couchbase.com/sdk-api/couchbase-java-client-${Dependencies.CouchbaseVersion}/",
"javadoc.org.apache.kudu.base_url" -> s"https://kudu.apache.org/releases/${Dependencies.KuduVersion}/apidocs/",
"javadoc.org.apache.hadoop.base_url" -> s"https://hadoop.apache.org/docs/r${Dependencies.HadoopVersion}/api/",
"javadoc.com.amazonaws.base_url" -> "https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/",
"javadoc.software.amazon.awssdk.base_url" -> "https://sdk.amazonaws.com/java/api/latest/",
// Eclipse Paho client for MQTT
"javadoc.org.eclipse.paho.client.mqttv3.base_url" -> "https://www.eclipse.org/paho/files/javadoc/",
"javadoc.org.bson.codecs.configuration.base_url" -> "https://mongodb.github.io/mongo-java-driver/3.7/javadoc/",
"scaladoc.scala.base_url" -> s"https://www.scala-lang.org/api/${scalaBinaryVersion.value}.x/",
"scaladoc.akka.stream.alpakka.base_url" -> {
val docsHost = sys.env
.get("CI")
.map(_ => "https://doc.akka.io")
.getOrElse(s"http://localhost:${(previewSite / previewFixedPort).value.getOrElse(4000)}")
s"$docsHost/api/alpakka/${if (isSnapshot.value) "snapshot" else version.value}/"
}
),
paradoxGroups := Map("Language" -> Seq("Java", "Scala")),
resolvers += Resolver.jcenterRepo,
publishRsyncArtifact := makeSite.value -> "www/",
Expand Down Expand Up @@ -361,9 +361,9 @@ def alpakkaProject(projectId: String, moduleName: String, additionalSettings: sb
name := s"akka-stream-alpakka-$projectId",
AutomaticModuleName.settings(s"akka.stream.alpakka.$moduleName"),
mimaPreviousArtifacts := Set(
organization.value %% name.value % previousStableVersion.value
.getOrElse(throw new Error("Unable to determine previous version"))
)
organization.value %% name.value % previousStableVersion.value
.getOrElse(throw new Error("Unable to determine previous version"))
)
)
.settings(additionalSettings: _*)

Expand Down
24 changes: 12 additions & 12 deletions csv/src/test/scala/akka/stream/alpakka/csv/CsvParserSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ class CsvParserSpec extends WordSpec with Matchers with OptionValues {
val parser = new CsvParser(',', '"', '\\', maximumLineLength)
parser.offer(in)
val exception = the[MalformedCsvException] thrownBy {
parser.poll(requireLineEnd = true)
}
parser.poll(requireLineEnd = true)
}
exception.getMessage should be("wrong escaping at 1:3, quote is escaped as \"\"")
exception.getLineNo should be(1)
exception.getBytePos should be(3)
Expand All @@ -117,8 +117,8 @@ class CsvParserSpec extends WordSpec with Matchers with OptionValues {
val parser = new CsvParser(',', '"', '\\', maximumLineLength)
parser.offer(in)
val exception = the[MalformedCsvException] thrownBy {
parser.poll(requireLineEnd = false)
}
parser.poll(requireLineEnd = false)
}
exception.getMessage should be("wrong escaping at 1:3, no character after escape")
}

Expand All @@ -127,8 +127,8 @@ class CsvParserSpec extends WordSpec with Matchers with OptionValues {
val parser = new CsvParser(',', '"', '\\', maximumLineLength)
parser.offer(in)
val exception = the[MalformedCsvException] thrownBy {
parser.poll(requireLineEnd = false)
}
parser.poll(requireLineEnd = false)
}
exception.getMessage should be("wrong escaping at 1:4, no character after escape")
}

Expand All @@ -137,8 +137,8 @@ class CsvParserSpec extends WordSpec with Matchers with OptionValues {
val parser = new CsvParser(',', '"', '\\', maximumLineLength)
parser.offer(in)
val exception = the[MalformedCsvException] thrownBy {
parser.poll(requireLineEnd = false)
}
parser.poll(requireLineEnd = false)
}
exception.getMessage should be("wrong escaping at 1:4, no character after escape")
}

Expand Down Expand Up @@ -237,8 +237,8 @@ class CsvParserSpec extends WordSpec with Matchers with OptionValues {
parser.offer(ByteString("\",B"))
parser.poll(requireLineEnd = true) should be('empty)
val exception = the[MalformedCsvException] thrownBy {
parser.poll(requireLineEnd = false)
}
parser.poll(requireLineEnd = false)
}
exception.getMessage should be("unclosed quote at end of input 1:6, no matching quote found")
}

Expand Down Expand Up @@ -293,8 +293,8 @@ class CsvParserSpec extends WordSpec with Matchers with OptionValues {
parser.offer(in)
parser.poll(requireLineEnd = true)
val exception = the[MalformedCsvException] thrownBy {
parser.poll(requireLineEnd = true)
}
parser.poll(requireLineEnd = true)
}
exception.getMessage should be("no line end encountered within 11 bytes on line 2")
}

Expand Down
15 changes: 7 additions & 8 deletions doc-examples/src/main/scala/ftpsamples/RotateLogsToFtp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ object RotateLogsToFtp extends ActorSystemAvailable with App {
// (2)
val rotator = () => {
var last: Char = ' '
(bs: ByteString) =>
{
bs.head.toChar match {
case char if char != last =>
last = char
Some(s"log-$char.z")
case _ => None
}
(bs: ByteString) => {
bs.head.toChar match {
case char if char != last =>
last = char
Some(s"log-$char.z")
case _ => None
}
}
}

// (3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ private[dynamodb] trait AwsClient[S <: AwsClientSettings] {
uri = signableUrl,
method = original.getHttpMethod,
headers = List(
headers.RawHeader("x-amz-date", amzHeaders.get("X-Amz-Date")),
headers.RawHeader("authorization", amzHeaders.get("Authorization")),
headers.RawHeader("x-amz-target", amzHeaders.get("X-Amz-Target"))
) ++ tokenHeader,
headers.RawHeader("x-amz-date", amzHeaders.get("X-Amz-Date")),
headers.RawHeader("authorization", amzHeaders.get("Authorization")),
headers.RawHeader("x-amz-target", amzHeaders.get("X-Amz-Target"))
) ++ tokenHeader,
entity = HttpEntity(defaultContentType, body)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ private[elasticsearch] final class ElasticsearchFlowStage[T, C](
val json = messages
.map { message =>
val sharedFields: Seq[(String, JsString)] = Seq(
"_index" -> JsString(message.indexName.getOrElse(indexName)),
typeNameTuple
) ++ message.customMetadata.map { case (field, value) => field -> JsString(value) }
"_index" -> JsString(message.indexName.getOrElse(indexName)),
typeNameTuple
) ++ message.customMetadata.map { case (field, value) => field -> JsString(value) }
val tuple: (String, JsObject) = message.operation match {
case Index =>
val fields = Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ private[elasticsearch] final class ElasticsearchSourceLogic[T](indexName: String
val completeParams = searchParams ++ extraParams.flatten

val searchBody = "{" + completeParams
.map {
case (name, json) =>
"\"" + name + "\":" + json
}
.mkString(",") + "}"
.map {
case (name, json) =>
"\"" + name + "\":" + json
}
.mkString(",") + "}"

val endpoint: String = (indexName, typeName) match {
case (i, Some(t)) => s"/$i/$t/_search"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ object LogRotatorSink {
f: function.Creator[function.Function[ByteString, Optional[C]]]
): () => ByteString => Option[C] = () => {
val fun = f.create()
elem =>
fun(elem).asScala
elem => fun(elem).asScala
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ object Directory {
require(Files.isDirectory(directory), s"Path must be a directory, $directory isn't")
val factory = maxDepth match {
case None =>
() =>
Files.walk(directory, fileVisitOptions: _*)
() => Files.walk(directory, fileVisitOptions: _*)
case Some(maxDepth) =>
() =>
Files.walk(directory, maxDepth, fileVisitOptions: _*)
() => Files.walk(directory, maxDepth, fileVisitOptions: _*)
}

StreamConverters.fromJavaStream(factory)
Expand Down
69 changes: 33 additions & 36 deletions file/src/test/scala/docs/scaladsl/LogRotatorSinkSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,17 @@ class LogRotatorSinkSpec
val testFunction = () => {
val max = 2002
var size: Long = max
(element: ByteString) =>
{
if (size + element.size > max) {
val path = Files.createTempFile(fs.getPath("/"), "test", ".log")
files :+= path
size = element.size
Option(path)
} else {
size += element.size
Option.empty[Path]
}
(element: ByteString) => {
if (size + element.size > max) {
val path = Files.createTempFile(fs.getPath("/"), "test", ".log")
files :+= path
size = element.size
Option(path)
} else {
size += element.size
Option.empty[Path]
}
}
}
val listFiles = () => files
(testFunction, listFiles)
Expand All @@ -84,8 +83,8 @@ class LogRotatorSinkSpec
"LogRotatorSink" must {

"complete when consuming an empty source" in assertAllStagesStopped {
val triggerCreator: () => ByteString => Option[Path] = () => { element: ByteString =>
fail("trigger creator should not be called")
val triggerCreator: () => ByteString => Option[Path] = () => {
element: ByteString => fail("trigger creator should not be called")
}

val rotatorSink: Sink[ByteString, Future[Done]] =
Expand Down Expand Up @@ -131,16 +130,15 @@ class LogRotatorSinkSpec

val timeBasedTriggerCreator: () => ByteString => Option[Path] = () => {
var currentFilename: Option[String] = None
(_: ByteString) =>
{
val newName = LocalDateTime.now().format(formatter)
if (currentFilename.contains(newName)) {
None
} else {
currentFilename = Some(newName)
Some(destinationDir.resolve(newName))
}
(_: ByteString) => {
val newName = LocalDateTime.now().format(formatter)
if (currentFilename.contains(newName)) {
None
} else {
currentFilename = Some(newName)
Some(destinationDir.resolve(newName))
}
}
}

val timeBasedSink: Sink[ByteString, Future[Done]] =
Expand Down Expand Up @@ -173,17 +171,16 @@ class LogRotatorSinkSpec
var files = Seq.empty[Path]
val triggerFunctionCreator = () => {
var fileName: String = null
(element: ByteString) =>
{
if (fileName == null) {
val path = Files.createTempFile(fs.getPath("/"), "test", ".log")
files :+= path
fileName = path.toString
Some(path)
} else {
None
}
(element: ByteString) => {
if (fileName == null) {
val path = Files.createTempFile(fs.getPath("/"), "test", ".log")
files :+= path
fileName = path.toString
Some(path)
} else {
None
}
}
}
val completion = Source(testByteStrings).runWith(LogRotatorSink(triggerFunctionCreator))
Await.result(completion, 3.seconds)
Expand Down Expand Up @@ -260,8 +257,8 @@ class LogRotatorSinkSpec

"function fail on path creation" in assertAllStagesStopped {
val ex = new Exception("my-exception")
val triggerFunctionCreator = () => { (x: ByteString) =>
{
val triggerFunctionCreator = () => {
(x: ByteString) => {
throw ex
}
}
Expand All @@ -273,8 +270,8 @@ class LogRotatorSinkSpec

"downstream fail on file write" in assertAllStagesStopped {
val path = Files.createTempFile(fs.getPath("/"), "test", ".log")
val triggerFunctionCreator = () => { (x: ByteString) =>
{
val triggerFunctionCreator = () => {
(x: ByteString) => {
Option(path)
}
}
Expand Down
Loading