Skip to content

Commit

Permalink
Upgrade scalafmt to 2.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Odomontois committed Sep 17, 2020
1 parent 39aeb45 commit e6207ab
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 107 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
.bloop
.tags
.attach_pid*
*/project/metals.sbt
metals.sbt
metals.sbt
.vscode
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ binPack.parentConstructors = true
maxColumn = 120
includeCurlyBraceInSelectChains = false
align.preset = most
version = "2.6.4"
version = "2.7.1"
trailingCommas = preserve
newlines.penalizeSingleSelectMultiArgList = false
newlines.alwaysBeforeMultilineDef = false
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ package object zioRouting {

private def setInterruption[R, E, A, X](zio: ZIO[R, E, A], promise: Promise[X], rt: Runtime[Any]): ZIO[R, E, A] = {
def setInterrupt(fiber: Fiber[Any, Any]) =
ZIO.effectTotal(promise.setInterruptHandler {
case _ => rt.unsafeRunAsync(fiber.interrupt)(_ => ())
ZIO.effectTotal(promise.setInterruptHandler { case _ =>
rt.unsafeRunAsync(fiber.interrupt)(_ => ())
})

zio.fork.tap(setInterrupt) >>= (_.join)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ object RunHttp {
G: Monad[G]
): G[Service[Request, Response]] =
resps
.foldM[G, HttpMuxer](HttpMuxer) {
case (mux, (name, svc)) => runnable.run(svc).map(s => mux withHandler Route(name, s))
.foldM[G, HttpMuxer](HttpMuxer) { case (mux, (name, svc)) =>
runnable.run(svc).map(s => mux withHandler Route(name, s))
}
.widen
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class MakerMacro(val c: blackbox.Context) extends ShapelessMacros with Singleton
private class RouteTreeMaker(impl: Option[Tree]) {
type DSL = DSLTree[Type]
def makeRouteTree(ft: Type, dsl: DSL, input: Tree): Tree = dsl match {
case DSLLeaf(resTyp, groups, key) =>
case DSLLeaf(resTyp, groups, key) =>
impl match {
case None => q"""{
$interface.makeResult[$ft, $resTyp]($input)($key, ..$groups)
Expand All @@ -136,7 +136,7 @@ class MakerMacro(val c: blackbox.Context) extends ShapelessMacros with Singleton
val rest = makeRouteTree(ft, DSLBranch(next, dsls), Ident(identName))
q"""$interface.serve[$ft, $pref]($input).apply(($ident) => $rest)"""

case DSLBranch(_, dsls) => makeRouteSumTree(ft, dsls, input)
case DSLBranch(_, dsls) => makeRouteSumTree(ft, dsls, input)
}

def makeRouteSumTree(ft: Type, dsls: Vector[DSL], input: Tree): Tree =
Expand All @@ -154,8 +154,8 @@ class MakerMacro(val c: blackbox.Context) extends ShapelessMacros with Singleton
case base: TypeSymbol if base != typ => base.toType
}.flatMap {
extractMeth(_, name)
}.collectFirst {
case x => x
}.collectFirst { case x =>
x
}
}

Expand Down Expand Up @@ -200,22 +200,22 @@ class MakerMacro(val c: blackbox.Context) extends ShapelessMacros with Singleton
}

def constructDslTree(t: Type, prefix: PrefixInfo[Type]): DSLTree[Type] = t match {
case Complete(res) =>
case Complete(res) =>
prefix.key match {
case Some(str) => DSLLeaf(res, prefix.groups, str)
case None =>
val typLine = (prefix.prefix :+ t).map(showType).mkString(" :> ")
abort(s"method key for $typLine is not defined")
}

case Cons(x, y) =>
case Cons(x, y) =>
val px = constructDefPrefix(x)
constructDslTree(y, prefix |+| px) match {
case DSLBranch(p2, cdn) => DSLBranch(px.prefix ++ p2, cdn)
case res => DSLBranch(px.prefix, Vector(res))
}

case Split(x, y) =>
case Split(x, y) =>
val t1 = constructDslTree(x, prefix)
constructDslTree(y, prefix) match {
case DSLBranch(Vector(), cdn) => DSLBranch(Vector(), t1 +: cdn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ class NamedImplMacros(val c: whitebox.Context) extends shapeless.CaseClassMacros
}

def extractMethods(tpe: Type): NList[(List[NList[Type]], Type)] =
tpe.decls.collect {
case s: MethodSymbol =>
symbolName(s) ->
(s.paramLists.map(lst => lst.map(p => symbolName(p) -> p.typeSignature)) -> s.returnType)
tpe.decls.collect { case s: MethodSymbol =>
symbolName(s) ->
(s.paramLists.map(lst => lst.map(p => symbolName(p) -> p.typeSignature)) -> s.returnType)
}.toList

def extractAlgebra(tpe: Type): NList[NList[Type]] =
Expand Down Expand Up @@ -104,13 +103,12 @@ class NamedImplMacros(val c: whitebox.Context) extends shapeless.CaseClassMacros

lazy val TraverseState(correct, outputTypes, errors, matches) = {
val implMap = methods.toMap
union.foldLeft(TraverseState()) {
case (state, (caseName, inputFields)) =>
implMap.get(caseName) match {
case None => state.failed(s"implementation for $caseName is not defined")
case Some((caseImpl, retType)) =>
traverseSingle(state, inputFields, caseImpl, retType, caseName)
}
union.foldLeft(TraverseState()) { case (state, (caseName, inputFields)) =>
implMap.get(caseName) match {
case None => state.failed(s"implementation for $caseName is not defined")
case Some((caseImpl, retType)) =>
traverseSingle(state, inputFields, caseImpl, retType, caseName)
}
}
}

Expand All @@ -125,16 +123,15 @@ class NamedImplMacros(val c: whitebox.Context) extends shapeless.CaseClassMacros
val keyType = KeyName(name)
val retFld = FieldType(keyType, retType)

val res = impl.flatten.foldLeft(init addType retFld) {
case (state, (paramName, parImplType)) =>
inputMap.get(paramName) match {
case None => state.failed(s"parameter $paramName in method $name not found in input")
case Some(parInputType) if parInputType <:< parImplType => state
case Some(parInputType) =>
state.failed(
s"parameter $paramName in method $name has type $parImplType not assignable from $parInputType in input"
)
}
val res = impl.flatten.foldLeft(init addType retFld) { case (state, (paramName, parImplType)) =>
inputMap.get(paramName) match {
case None => state.failed(s"parameter $paramName in method $name not found in input")
case Some(parInputType) if parInputType <:< parImplType => state
case Some(parInputType) =>
state.failed(
s"parameter $paramName in method $name has type $parImplType not assignable from $parInputType in input"
)
}
}

def matc = {
Expand All @@ -153,8 +150,8 @@ class NamedImplMacros(val c: whitebox.Context) extends shapeless.CaseClassMacros

lazy val output = mkCoproductTpe(outputTypes.toList)

lazy val implementation = matches.foldRight[Tree](q"input") {
case (ResultField(pat, res, key), next) => q"""input match{
lazy val implementation = matches.foldRight[Tree](q"input") { case (ResultField(pat, res, key), next) =>
q"""input match{
case Inl($pat) => Inl(labelled.field[$key]($res))
case Inr(input) => Inr($next)
} """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ class ParamMakerMacro(val c: whitebox.Context) extends SymbolMacros {
def extractNamesTypes(ref: Type): List[(String, Type)] = ref match {
case RefinedType(tpes, scope) =>
info(tpes)
scope.collect {
case m: MethodSymbol =>
info(m)
m.name.decodedName.toString -> m.returnType
scope.collect { case m: MethodSymbol =>
info(m)
m.name.decodedName.toString -> m.returnType
}.toList
case _ => List.empty
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ trait SwaggerBuilder {

def make(info: OpenApiInfo = OpenApiInfo()) = {
val openApiPaths =
paths.groupBy(_.path).map {
case (parts, specs) =>
parts.mkString("/", "/", "") ->
specs.collect { case PathSpec(_, Some(method), op, _, _) => method -> op }.toMap
paths.groupBy(_.path).map { case (parts, specs) =>
parts.mkString("/", "/", "") ->
specs.collect { case PathSpec(_, Some(method), op, _, _) => method -> op }.toMap
}
OpenApi(
info = info,
Expand All @@ -41,9 +40,8 @@ trait SwaggerBuilder {
schemas = types,
securitySchemes = auths
),
tags = tags.map {
case (name, descr) =>
OpenApiTag(name = name, description = descr.some)
tags = tags.map { case (name, descr) =>
OpenApiTag(name = name, description = descr.some)
}.toVector
)
}
Expand Down Expand Up @@ -125,21 +123,20 @@ object SwaggerBuilder {
case spec => spec
}
val types = {
self.types.map {
case (name, t) =>
val typ = descriptions.typ(name)

val setDescriptions =
(DescribedType.title.update(_, typ(TypeTarget.Title) orElse _)) andThen
(DescribedType.description.update(_, typ(TypeTarget.Type) orElse _)) andThen
(
(DescribedType.typ >> SwaggerType.objProp >> SwaggerObject.properties > every end).update(
_,
prop => SwaggerProperty.description.update(prop, typ(TypeTarget.Field(prop.name)) orElse _)
)
self.types.map { case (name, t) =>
val typ = descriptions.typ(name)

val setDescriptions =
(DescribedType.title.update(_, typ(TypeTarget.Title) orElse _)) andThen
(DescribedType.description.update(_, typ(TypeTarget.Type) orElse _)) andThen
(
(DescribedType.typ >> SwaggerType.objProp >> SwaggerObject.properties > every end).update(
_,
prop => SwaggerProperty.description.update(prop, typ(TypeTarget.Field(prop.name)) orElse _)
)
)

name -> setDescriptions(t)
name -> setDescriptions(t)
}
}
val tags = self.tags ++ {
Expand Down Expand Up @@ -274,8 +271,8 @@ object MkSwagger {

implicit def derivedComplete[T](implicit content: SwaggerContent[T]) =
single[Complete[T]](
op = OpenApiOp(responses = OpenApiResponses(codes = content.content.groupBy(_._1).map {
case (i, contents) => (i, OpenApiResponse.makeMany(contents.flatMap(_._2): _*))
op = OpenApiOp(responses = OpenApiResponses(codes = content.content.groupBy(_._1).map { case (i, contents) =>
(i, OpenApiResponse.makeMany(contents.flatMap(_._2): _*))
})),
typeList = TreeMap(content.collectTypes.toSeq: _*)
)
Expand Down
Loading

0 comments on commit e6207ab

Please sign in to comment.