Skip to content

Commit

Permalink
Reformat with scalafmt 2.7.5
Browse files Browse the repository at this point in the history
Executed command: scalafmt --non-interactive
  • Loading branch information
scalameta-bot committed Apr 17, 2024
1 parent c93f921 commit be37fdd
Show file tree
Hide file tree
Showing 23 changed files with 135 additions and 132 deletions.
6 changes: 4 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ commands += Command.command("taskready") { s =>
}

lazy val warnUnusedImport = Def.setting {
if (scalaVersion.value.startsWith("2.13") ||
scalaVersion.value.startsWith("3.")) "-Wunused:imports"
if (
scalaVersion.value.startsWith("2.13") ||
scalaVersion.value.startsWith("3.")
) "-Wunused:imports"
else "-Ywarn-unused-import"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ class Macros(val c: blackbox.Context) {
val fallback = q"tmp.$getter"
q"conf.getSettingOrElse[$P](settings.unsafeGet($name), $fallback)"
}
val product = params.foldLeft(next(head)) {
case (accum, param) => q"$accum.product(${next(param)})"
val product = params.foldLeft(next(head)) { case (accum, param) =>
q"$accum.product(${next(param)})"
}
val tupleExtract = 1.to(params.length).foldLeft(q"t": Tree) {
case (accum, _) => q"$accum._1"
Expand Down Expand Up @@ -168,8 +168,8 @@ class Macros(val c: blackbox.Context) {
val fallback = q"tmp.$getter"
q"Conf.getSettingEx[$P]($fallback, conf, settings.unsafeGet($name))"
}
val product = params.foldLeft(next(head)) {
case (accum, param) => q"$accum.product(${next(param)})"
val product = params.foldLeft(next(head)) { case (accum, param) =>
q"$accum.product(${next(param)})"
}
val tupleExtract = 1.to(params.length).foldLeft(q"t": Tree) {
case (accum, _) => q"$accum._1"
Expand Down
66 changes: 32 additions & 34 deletions metaconfig-core/shared/src/main/scala/metaconfig/ConfError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ sealed abstract class ConfError(val msg: String) extends Serializable { self =>
val sb = new StringWriter()
val out = new PrintWriter(sb)
if (extra.nonEmpty) out.println(s"${extra.length + 1} errors")
all.zipWithIndex.foreach {
case (err, i) => out.append(s"[E$i] ").println(err)
all.zipWithIndex.foreach { case (err, i) =>
out.append(s"[E$i] ").println(err)
}
sb.toString
}
Expand Down Expand Up @@ -149,8 +149,8 @@ object ConfError {
val pathSuffix = if (path.isEmpty) "" else s" at '$path'"
new ConfError(
s"""Type mismatch$pathSuffix;
| found : $obtained
| expected : $expected""".stripMargin
| found : $obtained
| expected : $expected""".stripMargin
) {
override def isTypeMismatch: Boolean = true
}
Expand Down Expand Up @@ -194,18 +194,17 @@ object ConfError {
valid: Iterable[String]
)(implicit dummy: DummyImplicit): Option[ConfError] = {
val candidates = valid.toSeq
val errors = invalid.toList.map {
case (field, pos) =>
val closestCandidate = Levenshtein.closestCandidate(field, candidates)
val didYouMean = closestCandidate match {
case None =>
""
case Some(candidate) =>
s"\n\tDid you mean '$candidate'?"
}
message(
s"found option '$field' which wasn't expected, or isn't valid in this context.$didYouMean"
).atPos(pos)
val errors = invalid.toList.map { case (field, pos) =>
val closestCandidate = Levenshtein.closestCandidate(field, candidates)
val didYouMean = closestCandidate match {
case None =>
""
case Some(candidate) =>
s"\n\tDid you mean '$candidate'?"
}
message(
s"found option '$field' which wasn't expected, or isn't valid in this context.$didYouMean"
).atPos(pos)
}
apply(errors)
}
Expand All @@ -219,24 +218,23 @@ object ConfError {
val tail = values.tail
if (tail.isEmpty) head else f(head, tail)
}
seqToOpt(errors) {
case (head, tail) =>
new ConfError(head.stackTrace) {
override def extra: List[String] =
head.extra ++ tail.flatMap(x => x.stackTrace :: x.extra)
override def typeMismatch: Option[TypeMismatch] =
errors.view.flatMap(_.typeMismatch).headOption
override def isParseError: Boolean = errors.exists(_.isParseError)
override def isMissingField: Boolean = errors.exists(_.isMissingField)

override def cause: Option[Throwable] =
seqToOpt(errors.flatMap {
_.cause match {
case Some(c: CompositeException) => c.all
case x => x
}
}) { case (head, tail) => CompositeException(head, tail.toList) }
}
seqToOpt(errors) { case (head, tail) =>
new ConfError(head.stackTrace) {
override def extra: List[String] =
head.extra ++ tail.flatMap(x => x.stackTrace :: x.extra)
override def typeMismatch: Option[TypeMismatch] =
errors.view.flatMap(_.typeMismatch).headOption
override def isParseError: Boolean = errors.exists(_.isParseError)
override def isMissingField: Boolean = errors.exists(_.isMissingField)

override def cause: Option[Throwable] =
seqToOpt(errors.flatMap {
_.cause match {
case Some(c: CompositeException) => c.all
case x => x
}
}) { case (head, tail) => CompositeException(head, tail.toList) }
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion metaconfig-core/shared/src/main/scala/metaconfig/Input.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ sealed abstract class Input(val path: String, val text: String)
}
// If the file doesn't end with \n, then it's simply last_line:last_col+1.
// But if the file does end with \n, then it's last_line+1:0.
if (offset == chars.length && (0 < chars.length && chars(offset - 1) == '\n')) {
if (
offset == chars.length && (0 < chars.length && chars(offset - 1) == '\n')
) {
return a.length - 1
}
var lo = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import java.nio.charset.StandardCharsets
import metaconfig.generic.Settings
import metaconfig.ConfDecoder

abstract class Command[T](val name: String)(
implicit val _settings: Settings[T],
abstract class Command[T](val name: String)(implicit
val _settings: Settings[T],
confEncoder: ConfEncoder[T],
confDecoder: ConfDecoder[T]
) { self =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ object HelpOptions {
ConfEncoder.StringEncoder.contramap[HelpOptions](_.subcommand.mkString(" "))
implicit val decoder: ConfDecoder[HelpOptions] = ConfDecoder.from {
case Obj(
List(("remainingArgs", Conf.Lst(subcommands)))
List(("remainingArgs", Conf.Lst(subcommands)))
) =>
Configured.ok(HelpOptions(subcommands.collect {
case Conf.Str(command) => command
Configured.ok(HelpOptions(subcommands.collect { case Conf.Str(command) =>
command
}))
case _ =>
Configured.ok(HelpOptions(Nil))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ object Messages {
default: T
)(implicit encoder: ConfEncoder[T], settings: Settings[T]): Doc = {
val obj = ConfEncoder[T].writeObj(default)
val docs = settings.settings.zip(obj.values).flatMap {
case (setting, (_, value)) =>
val docs =
settings.settings.zip(obj.values).flatMap { case (setting, (_, value)) =>
if (setting.annotations.exists(_.isInstanceOf[Inline])) {
for {
underlying <- setting.underlying.toList
Expand All @@ -30,7 +30,7 @@ object Messages {
} else {
List(printOption(setting, value))
}
}
}
Doc.intercalate(Doc.line, docs.filter(_.nonEmpty))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ object TabCompleteCommand extends Command[TabCompleteOptions]("tab-complete") {
context: TabCompletionContext
): List[TabCompletionItem] = {
context.allSettings
.filterNot {
case (_, setting) => setting.isPositionalArgument
.filterNot { case (_, setting) =>
setting.isPositionalArgument
}
.keys
.toList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ object TabCompleteOptions {
(obj.getOption[Int]("current") |@|
obj.getOption[String]("format") |@|
obj.get[List[String]]("remainingArgs"))
.map {
case ((a, b), c) => TabCompleteOptions(a, b, c)
.map { case ((a, b), c) =>
TabCompleteOptions(a, b, c)
}
case _ =>
Configured.ok(TabCompleteOptions())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package metaconfig.generic

import scala.annotation.StaticAnnotation

/**
* Metadata about one field of a class.
/** Metadata about one field of a class.
*
* @param name the parameter name of this field.
* @param tpe the pretty-printed type of this parameter
Expand All @@ -18,8 +17,7 @@ final class Field(
def withName(newName: String) =
new Field(newName, tpe, annotations, underlying)

/**
* Returns this field with all underlying fields expaneded.
/** Returns this field with all underlying fields expaneded.
*
* Underlying field names become prefixed by their enclosing fields.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ final class Setting(val field: Field) {
case _ => false
}
def tabCompleteOneOf: Option[List[String]] =
annotations.collectFirst {
case oneof: TabCompleteAsOneOf => oneof.options.toList
annotations.collectFirst { case oneof: TabCompleteAsOneOf =>
oneof.options.toList
}
@deprecated("Use isDynamic instead", "0.8.2")
def isMap: Boolean = field.tpe.startsWith("Map")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ final class Settings[T](
case DescriptionDoc(doc) => doc
case Description(doc) => Doc.text(doc)
}
def cliUsage: Option[Doc] = annotations.collectFirst {
case Usage(doc) => Doc.text(doc)
def cliUsage: Option[Doc] = annotations.collectFirst { case Usage(doc) =>
Doc.text(doc)
}
def cliExamples: List[Doc] = annotations.collect {
case ExampleUsage(example) => Doc.text(example)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package metaconfig.generic

import scala.annotation.StaticAnnotation

/**
* Aggregated metadata about a given type.
/** Aggregated metadata about a given type.
*
* @param fields the fields of this type
* @tparam T not used for anything but to drive implicit resolution.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,26 @@ import metaconfig.Configured

object CanBuildFromDecoder {

def map[A, CC[_, _]](
implicit ev: ConfDecoder[A],
def map[A, CC[_, _]](implicit
ev: ConfDecoder[A],
factory: Factory[(String, A), CC[String, A]],
classTag: ClassTag[A]
): ConfDecoder[CC[String, A]] =
ConfDecoder.fromPartial(
s"Map[String, ${classTag.runtimeClass.getName}]"
) {
case Conf.Obj(values) =>
build(values, ev, factory)(_._2, (x, y) => (x._1, y))
) { case Conf.Obj(values) =>
build(values, ev, factory)(_._2, (x, y) => (x._1, y))
}

def list[C[_], A](
implicit ev: ConfDecoder[A],
def list[C[_], A](implicit
ev: ConfDecoder[A],
factory: Factory[A, C[A]],
classTag: ClassTag[A]
): ConfDecoder[C[A]] =
ConfDecoder.fromPartial(
s"List[${classTag.runtimeClass.getName}]"
) {
case Conf.Lst(values) =>
build(values, ev, factory)(identity, (_, x) => x)
) { case Conf.Lst(values) =>
build(values, ev, factory)(identity, (_, x) => x)
}

private def build[A, B, C, Coll](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ object Cli {
case els => ConfError.typeMismatch("Conf.Obj", els).notOk.get
}

val keyValues = settings.settings.zip(defaultConf).flatMap {
case (setting, value) =>
val keyValues =
settings.settings.zip(defaultConf).flatMap { case (setting, value) =>
if (setting.isHidden) {
Nil
} else if (setting.annotations.exists(_.isInstanceOf[Inline])) {
Expand All @@ -35,7 +35,7 @@ object Cli {
} else {
toHelp(setting, value) :: Nil
}
}
}
tabulate(keyValues)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ object ConfGet {
): Configured[T] =
getKey(conf, path +: extraNames).fold(Configured.ok(default))(ev.read)

def get[T](conf: Conf, path: String, extraNames: String*)(
implicit ev: ConfDecoder[T]
def get[T](conf: Conf, path: String, extraNames: String*)(implicit
ev: ConfDecoder[T]
): Configured[T] = {
conf match {
case obj: Conf.Obj =>
Expand All @@ -45,8 +45,8 @@ object ConfGet {
}
}

def getNested[T](conf: Conf, keys: String*)(
implicit ev: ConfDecoder[T]
def getNested[T](conf: Conf, keys: String*)(implicit
ev: ConfDecoder[T]
): Configured[T] =
conf.getNestedConf(keys: _*).andThen(ev.read)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ import metaconfig.Conf
object ConfPatch {
def patch(original: Conf, revised: Conf): Conf = (original, revised) match {
case (Conf.Obj(a), Conf.Obj(b)) =>
Conf.Obj(b.flatMap {
case kv @ (k, v) =>
if (a.contains(kv)) Nil
else {
a.find(_._1 == k) match {
case Some((_, v1)) =>
(k, patch(v1, v)) :: Nil
case _ =>
kv :: Nil
}
Conf.Obj(b.flatMap { case kv @ (k, v) =>
if (a.contains(kv)) Nil
else {
a.find(_._1 == k) match {
case Some((_, v1)) =>
(k, patch(v1, v)) :: Nil
case _ =>
kv :: Nil
}
}
})
case (a, b) =>
b
Expand Down
Loading

0 comments on commit be37fdd

Please sign in to comment.