Skip to content

Commit

Permalink
Update scalafmt-core to 2.7.0 (#821)
Browse files Browse the repository at this point in the history
Co-authored-by: Rui Gonçalves <ruippeixotog@gmail.com>
  • Loading branch information
scala-steward and ruippeixotog committed Sep 8, 2020
1 parent f662eff commit 988ac89
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
@@ -1,4 +1,4 @@
version = 2.6.4
version = 2.7.0

align.preset = none
maxColumn = 120
4 changes: 2 additions & 2 deletions core/src/main/scala/pureconfig/ConfigCursor.scala
Expand Up @@ -447,8 +447,8 @@ case class ConfigListCursor(listValue: ConfigList, pathElems: List[String], offs
* @return a list of cursors to the elements of the config list pointed to by this cursor.
*/
def list: List[ConfigCursor] =
listValue.asScala.toList.drop(offset).zipWithIndex.map {
case (cv, idx) => ConfigCursor(cv, indexKey(idx) :: pathElems)
listValue.asScala.toList.drop(offset).zipWithIndex.map { case (cv, idx) =>
ConfigCursor(cv, indexKey(idx) :: pathElems)
}

// Avoid resetting the offset when using ConfigCursor's implementation.
Expand Down
18 changes: 8 additions & 10 deletions core/src/main/scala/pureconfig/configurable/package.scala
Expand Up @@ -54,13 +54,12 @@ package object configurable {
)(implicit readerV: Derivation[ConfigReader[V]]): ConfigReader[Map[K, V]] =
ConfigReader.fromCursor { cursor =>
cursor.asMap.right.flatMap { map =>
map.foldLeft[ConfigReader.Result[Map[K, V]]](Right(Map.empty)) {
case (acc, (key, valueCursor)) =>
val eitherKeyOrError = cursor.scopeFailure(keyParser(key))
val eitherValueOrError = readerV.value.from(valueCursor)
ConfigReader.Result.zipWith(acc, ConfigReader.Result.zipWith(eitherKeyOrError, eitherValueOrError)(_ -> _))(
_ + _
)
map.foldLeft[ConfigReader.Result[Map[K, V]]](Right(Map.empty)) { case (acc, (key, valueCursor)) =>
val eitherKeyOrError = cursor.scopeFailure(keyParser(key))
val eitherValueOrError = readerV.value.from(valueCursor)
ConfigReader.Result.zipWith(acc, ConfigReader.Result.zipWith(eitherKeyOrError, eitherValueOrError)(_ -> _))(
_ + _
)
}
}
}
Expand All @@ -69,9 +68,8 @@ package object configurable {
keyFormatter: K => String
)(implicit writerV: Derivation[ConfigWriter[V]]): ConfigWriter[Map[K, V]] =
ConfigWriter.fromFunction[Map[K, V]](map =>
ConfigValueFactory.fromMap(map.map {
case (key, value) =>
keyFormatter(key) -> writerV.value.to(value)
ConfigValueFactory.fromMap(map.map { case (key, value) =>
keyFormatter(key) -> writerV.value.to(value)
}.asJava)
)
}
11 changes: 5 additions & 6 deletions core/src/main/scala/pureconfig/error/ConfigReaderFailures.scala
Expand Up @@ -41,12 +41,11 @@ case class ConfigReaderFailures(head: ConfigReaderFailure, tail: ConfigReaderFai
linesBuffer += ""
}

failuresByPath.foreach {
case (p, failures) =>
linesBuffer += (tabs(0) + (if (p.isEmpty) s"at the root:" else s"at '$p':"))
failures.foreach { failure =>
linesBuffer += descriptionWithOrigin(failure, 1)
}
failuresByPath.foreach { case (p, failures) =>
linesBuffer += (tabs(0) + (if (p.isEmpty) s"at the root:" else s"at '$p':"))
failures.foreach { failure =>
linesBuffer += descriptionWithOrigin(failure, 1)
}
}
linesBuffer.mkString(System.lineSeparator())
}
Expand Down
2 changes: 1 addition & 1 deletion example/.scalafmt.conf
@@ -1,4 +1,4 @@
version = 2.6.4
version = 2.7.0

align.preset = none
maxColumn = 120
9 changes: 4 additions & 5 deletions macros/src/main/scala/pureconfig/Derivation.scala
Expand Up @@ -206,11 +206,10 @@ class DerivationMacros(val c: whitebox.Context) extends LazyContextParser with M
}
}

failuresByDirectReason.foreach {
case (typ, innerReasons) =>
val msgEnding = if (innerReasons.isEmpty) "" else ", because:"
builder ++= s"${" " * depth}- missing ${prettyPrintType(typ)}$msgEnding\n"
buildMessage(innerReasons, depth + 1)
failuresByDirectReason.foreach { case (typ, innerReasons) =>
val msgEnding = if (innerReasons.isEmpty) "" else ", because:"
builder ++= s"${" " * depth}- missing ${prettyPrintType(typ)}$msgEnding\n"
buildMessage(innerReasons, depth + 1)
}
}

Expand Down
Expand Up @@ -56,8 +56,8 @@ trait LazyContextParser {
}
shapeless.Lazy.apply[${_}]($outerRef)
}""" if isRefTo(outerRef, outer) && isRefTo(anonClassRef, anonClass) =>
val lazyDefMap: Map[TermName, Tree] = lazyDefs.collect {
case q"lazy val $valName = $valBody" => valName -> valBody
val lazyDefMap: Map[TermName, Tree] = lazyDefs.collect { case q"lazy val $valName = $valBody" =>
valName -> valBody
}.toMap

val entrypointDef = lazyDefMap(entrypoint)
Expand Down
Expand Up @@ -33,9 +33,8 @@ package object instances {
fa.contramap(f)

def product[A, B](fa: ConfigWriter[A], fb: ConfigWriter[B]) =
ConfigWriter.fromFunction[(A, B)] {
case (a, b) =>
fb.to(b).withFallback(fa.to(a))
ConfigWriter.fromFunction[(A, B)] { case (a, b) =>
fb.to(b).withFallback(fa.to(a))
}
}

Expand All @@ -46,9 +45,8 @@ package object instances {

def product[A, B](fa: ConfigConvert[A], fb: ConfigConvert[B]): ConfigConvert[(A, B)] = {
val reader = fa.zip(fb)
val writer = ConfigWriter.fromFunction[(A, B)] {
case (a, b) =>
fb.to(b).withFallback(fa.to(a))
val writer = ConfigWriter.fromFunction[(A, B)] { case (a, b) =>
fb.to(b).withFallback(fa.to(a))
}

ConfigConvert.fromReaderAndWriter(Derivation.Successful(reader), Derivation.Successful(writer))
Expand Down
Expand Up @@ -16,9 +16,8 @@ final case class NoValidCoproductOptionFound(value: ConfigValue, optionFailures:
baseDescription + (if (optionFailures.isEmpty) ""
else {
"\n" + optionFailures
.map {
case (optionName, failures) =>
s"Can't use coproduct option '$optionName':\n" + failures.prettyPrint(1)
.map { case (optionName, failures) =>
s"Can't use coproduct option '$optionName':\n" + failures.prettyPrint(1)
}
.mkString("\n")
})
Expand Down
Expand Up @@ -26,8 +26,8 @@ object CoproductReaderOptions {
lazy val options = {
val optionName = hName.value.name
val optionReader = hConfigReader.value.value.map[FieldType[Name, H] :+: T](v => Inl(field[Name](v)))
val remaining = tConfigReaderOptions.value.options.map {
case (name, reader) => name -> reader.map[FieldType[Name, H] :+: T](Inr.apply)
val remaining = tConfigReaderOptions.value.options.map { case (name, reader) =>
name -> reader.map[FieldType[Name, H] :+: T](Inr.apply)
}
remaining.updated(optionName, optionReader)
}
Expand Down
Expand Up @@ -40,9 +40,8 @@ object MapShapedWriter {
val kv = hint.to(valueOpt, key.value.name)

// TODO check that all keys are unique
kv.fold(rem) {
case (k, v) =>
rem.asInstanceOf[ConfigObject].withValue(k, v)
kv.fold(rem) { case (k, v) =>
rem.asInstanceOf[ConfigObject].withValue(k, v)
}
}
}
Expand Down
Expand Up @@ -59,8 +59,8 @@ object MagnoliaConfigReader {
if (listCur.size != ctx.parameters.length) {
cur.failed(WrongSizeList(ctx.parameters.length, listCur.size))
} else {
val fields = ConfigReader.Result.sequence(ctx.parameters.zip(listCur.list).map {
case (param, cur) => param.typeclass.from(cur)
val fields = ConfigReader.Result.sequence(ctx.parameters.zip(listCur.list).map { case (param, cur) =>
param.typeclass.from(cur)
})
fields.map(ctx.rawConstruct)
}
Expand Down
12 changes: 6 additions & 6 deletions tests/src/main/scala/pureconfig/ConfigConvertChecks.scala
Expand Up @@ -125,10 +125,10 @@ trait ConfigConvertChecks { this: AnyFlatSpec with Matchers with ScalaCheckDrive
for (value <- values) {
it should s"fail when it tries to read a value of type ${tpe.tpe} " +
s"from ${value.render(ConfigRenderOptions.concise())}" in {
val result = cr.from(value)
result.left.value.toList should have size 1
result.left.value.head should matchPattern { case ConvertFailure(_: E, _, _) => }
}
val result = cr.from(value)
result.left.value.toList should have size 1
result.left.value.head should matchPattern { case ConvertFailure(_: E, _, _) => }
}
}

/**
Expand All @@ -142,7 +142,7 @@ trait ConfigConvertChecks { this: AnyFlatSpec with Matchers with ScalaCheckDrive
for ((value, errors) <- valuesToErrors) {
it should s"fail when it tries to read a value of type ${tpe.tpe} " +
s"from ${value.render(ConfigRenderOptions.concise())}" in {
cr.from(value).left.value.toList should contain theSameElementsAs errors.toList
}
cr.from(value).left.value.toList should contain theSameElementsAs errors.toList
}
}
}
8 changes: 4 additions & 4 deletions tests/src/test/scala/pureconfig/ApiSuite.scala
Expand Up @@ -123,17 +123,17 @@ class ApiSuite extends BaseSuite {
case class Conf(s: String, b: Boolean, sref: String) // sref defined in reference.conf
val path = createTempFile("""{ b: true, s: "str" }""")
loadConfig[Conf](path = path) shouldBe Right(Conf("str", true, "wow"))
loadConfig[Conf](path = nonExistingPath) should failLike {
case CannotReadFile(path, _) => be(path)(nonExistingPath)
loadConfig[Conf](path = nonExistingPath) should failLike { case CannotReadFile(path, _) =>
be(path)(nonExistingPath)
}
}

it should "loadConfig from a configuration file with a namespace" in {
case class Conf(s: String, b: Boolean, sref: String) // foo.bar.sref defined in reference.conf
val path = createTempFile("""foo.bar { b: true, s: "str" }""")
loadConfig[Conf](path = path, namespace = "foo.bar") shouldBe Right(Conf("str", true, "foowow"))
loadConfig[Conf](path = nonExistingPath, namespace = "foo.bar") should failLike {
case CannotReadFile(path, _) => be(path)(nonExistingPath)
loadConfig[Conf](path = nonExistingPath, namespace = "foo.bar") should failLike { case CannotReadFile(path, _) =>
be(path)(nonExistingPath)
}
loadConfig[Conf](path = path, namespace = "bar.foo") should failWith(KeyNotFound("bar", Set.empty))
}
Expand Down
20 changes: 10 additions & 10 deletions tests/src/test/scala/pureconfig/ConfigSourceSuite.scala
Expand Up @@ -95,17 +95,17 @@ class ConfigSourceSuite extends BaseSuite {
case class Conf(s: String, b: Boolean)
val path = createTempFile("""{ b: true, s: "str" }""")
ConfigSource.file(path).load[Conf] shouldBe Right(Conf("str", true))
ConfigSource.file(nonExistingPath).load[Conf] should failLike {
case CannotReadFile(path, _) => be(path)(nonExistingPath)
ConfigSource.file(nonExistingPath).load[Conf] should failLike { case CannotReadFile(path, _) =>
be(path)(nonExistingPath)
}
}

it should "allow reading from a configuration file at a namespace" in {
case class Conf(s: String, b: Boolean)
val path = createTempFile("""foo.bar { b: true, s: "str" }""")
ConfigSource.file(path).at("foo.bar").load[Conf] shouldBe Right(Conf("str", true))
ConfigSource.file(nonExistingPath).at("foo.bar").load[Conf] should failLike {
case CannotReadFile(path, _) => be(path)(nonExistingPath)
ConfigSource.file(nonExistingPath).at("foo.bar").load[Conf] should failLike { case CannotReadFile(path, _) =>
be(path)(nonExistingPath)
}
ConfigSource.file(path).at("bar.foo").load[Conf] should failWith(KeyNotFound("bar", Set.empty))
}
Expand All @@ -114,8 +114,8 @@ class ConfigSourceSuite extends BaseSuite {
case class Conf(s: String, b: Boolean)
val path = createTempFile("""{ b: true, s: "str" }""")
ConfigSource.url(path.toUri.toURL).load[Conf] shouldBe Right(Conf("str", true))
ConfigSource.url(nonExistingPath.toUri.toURL).load[Conf] should failLike {
case CannotReadUrl(url, _) => be(url)(nonExistingPath.toUri.toURL)
ConfigSource.url(nonExistingPath.toUri.toURL).load[Conf] should failLike { case CannotReadUrl(url, _) =>
be(url)(nonExistingPath.toUri.toURL)
}
}

Expand Down Expand Up @@ -229,12 +229,12 @@ class ConfigSourceSuite extends BaseSuite {
case class Conf(hostOverride: String)
val resolve1 = ConfigSource.resources("conf/configSource/resolve1.conf")

resolve1.value() should failLike {
case CannotParse(msg, _) => be(msg)(s"Could not resolve substitution to a value: $${host-suffix}")
resolve1.value() should failLike { case CannotParse(msg, _) =>
be(msg)(s"Could not resolve substitution to a value: $${host-suffix}")
}

resolve1.load[Conf] should failLike {
case CannotParse(msg, _) => be(msg)(s"Could not resolve substitution to a value: $${host-suffix}")
resolve1.load[Conf] should failLike { case CannotParse(msg, _) =>
be(msg)(s"Could not resolve substitution to a value: $${host-suffix}")
}
}

Expand Down
5 changes: 2 additions & 3 deletions tests/src/test/scala/pureconfig/DurationUtilsSuite.scala
Expand Up @@ -98,9 +98,8 @@ class DurationUtilsSuite extends BaseSuite {
fromS(fromD(expected)).right.value shouldBe expected
}
it should "freak when given a value larger than 2^64" in {
dcc.from(scc.to("12345678901234567890 ns")) should failLike {
case ConvertFailure(ExceptionThrown(ex), _, _) =>
(include regex "trying to construct too large duration")(ex.getMessage)
dcc.from(scc.to("12345678901234567890 ns")) should failLike { case ConvertFailure(ExceptionThrown(ex), _, _) =>
(include regex "trying to construct too large duration")(ex.getMessage)
}
}
it should "parse a fractional value" in {
Expand Down

0 comments on commit 988ac89

Please sign in to comment.