Skip to content

Commit

Permalink
Upgrade ScalaFmt (#1097)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostdogpr authored Oct 16, 2021
1 parent 27ac36f commit 1311119
Show file tree
Hide file tree
Showing 47 changed files with 181 additions and 185 deletions.
18 changes: 13 additions & 5 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
version = "2.7.5"
version = "3.0.6"

runner.dialect = scala213
maxColumn = 120
align = most
align.preset = most
continuationIndent.defnSite = 2
assumeStandardLibraryStripMargin = true
docstrings = JavaDoc
docstrings.style = Asterisk
docstrings.wrap = no
lineEndings = preserve
includeCurlyBraceInSelectChains = false
danglingParentheses = true
danglingParentheses.preset = true
spaces {
inImportCurlyBraces = true
}
optIn.annotationNewlines = true

rewrite.rules = [SortImports, RedundantBraces]
rewrite.rules = [SortImports, RedundantBraces]

fileOverride {
"glob:**/scala-3/**" {
runner.dialect = scala3
}
}
16 changes: 7 additions & 9 deletions adapters/zio-http/src/main/scala/caliban/ZHttpAdapter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ object ZHttpAdapter {
val routes = Socket.collect[WebSocketFrame] { case Text(text) =>
ZStream
.fromEffect(ZIO.fromEither(decode[GraphQLWSRequest](text)))
.collect({
.collect {
case GraphQLWSRequest("connection_init", id, payload) =>
val before = (callbacks.beforeInit, payload) match {
case (Some(beforeInit), Some(payload)) =>
Expand Down Expand Up @@ -218,7 +218,7 @@ object ZHttpAdapter {
case GraphQLWSRequest("stop", id, _) =>
removeSubscription(id, subscriptions) *> ZStream.empty

})
}
.flatten
.catchAll(_ => connectionError)
}
Expand All @@ -227,11 +227,9 @@ object ZHttpAdapter {
}

private def queryFromQueryParams(req: Request) = {
val params = List("query", "operationName", "variables", "extensions")
.collect({ case k =>
k -> req.url.queryParams.get(k).flatMap(_.headOption).getOrElse("")
})
.toMap
val params = List("query", "operationName", "variables", "extensions").collect { case k =>
k -> req.url.queryParams.get(k).flatMap(_.headOption).getOrElse("")
}.toMap
ZIO.fromEither(decode[GraphQLRequest](params.asJson.noSpaces))
}

Expand Down Expand Up @@ -289,13 +287,13 @@ object ZHttpAdapter {
.foldCause(cause => GraphQLResponse(NullValue, cause.defects).asJson, _.asJson)

implicit class HttpErrorOps[R, E <: Throwable, A](private val zio: ZIO[R, io.circe.Error, A]) extends AnyVal {
def handleHTTPError: ZIO[R, HttpError, A] = zio.mapError({
def handleHTTPError: ZIO[R, HttpError, A] = zio.mapError {
case DecodingFailure(error, _) =>
HttpError.BadRequest.apply(s"Invalid json: $error")
case ParsingFailure(message, _) =>
HttpError.BadRequest.apply(message)
case t: Throwable => HttpError.InternalServerError.apply("Internal Server Error", Some(t.getCause))
})
}
}

private val protocol = SocketProtocol.subProtocol("graphql-ws")
Expand Down
34 changes: 17 additions & 17 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ val zioHttpVersion = "1.0.0.0-RC17"

inThisBuild(
List(
scalaVersion := scala212,
crossScalaVersions := allScala,
organization := "com.github.ghostdogpr",
homepage := Some(url("https://github.com/ghostdogpr/caliban")),
licenses := List(
scalaVersion := scala212,
crossScalaVersions := allScala,
organization := "com.github.ghostdogpr",
homepage := Some(url("https://github.com/ghostdogpr/caliban")),
licenses := List(
"Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")
),
Test / parallelExecution := false,
scmInfo := Some(
scmInfo := Some(
ScmInfo(
url("https://github.com/ghostdogpr/caliban/"),
"scm:git:[email protected]:ghostdogpr/caliban.git"
)
),
developers := List(
developers := List(
Developer(
"ghostdogpr",
"Pierre Ricadat",
Expand Down Expand Up @@ -136,7 +136,7 @@ lazy val core = project
.dependsOn(macros)
.settings(
Test / fork := true,
run / fork := true
run / fork := true
)

lazy val tools = project
Expand Down Expand Up @@ -164,25 +164,25 @@ lazy val codegenSbt = project
.settings(commonSettings)
.enablePlugins(BuildInfoPlugin)
.settings(
buildInfoKeys := Seq[BuildInfoKey](version),
buildInfoKeys := Seq[BuildInfoKey](version),
buildInfoPackage := "caliban.codegen",
buildInfoObject := "BuildInfo"
buildInfoObject := "BuildInfo"
)
.settings(
sbtPlugin := true,
sbtPlugin := true,
crossScalaVersions := Seq(scala212),
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework")),
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework")),
libraryDependencies ++= Seq(
"dev.zio" %% "zio-test-sbt" % zioVersion % Test
)
)
.enablePlugins(SbtPlugin)
.settings(
scriptedLaunchOpts := {
scriptedLaunchOpts := {
scriptedLaunchOpts.value ++
Seq("-Xmx1024M", "-Xss4M", "-Dplugin.version=" + version.value)
},
scriptedBufferLog := false,
scriptedBufferLog := false,
scriptedDependencies := {
(macros / publishLocal).value
(core / publishLocal).value
Expand Down Expand Up @@ -372,7 +372,7 @@ lazy val clientLaminext = crossProject(JSPlatform)
.settings(commonSettings)
.dependsOn(clientJS)
.settings(
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework")),
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework")),
Test / scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.ESModule) },
Test / scalaJSLinkerConfig ~= { _.withModuleSplitStyle(ModuleSplitStyle.FewestModules) },
Test / scalaJSLinkerConfig ~= { _.withSourceMap(false) },
Expand All @@ -394,7 +394,7 @@ lazy val examples = project
.settings(commonSettings)
.settings(
publish / skip := true,
run / fork := true
run / fork := true
)
.settings(
crossScalaVersions -= scala3,
Expand Down Expand Up @@ -442,7 +442,7 @@ lazy val federation = project
.settings(commonSettings)
.dependsOn(core % "compile->compile;test->test")
.settings(
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework")),
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework")),
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % zioVersion,
"dev.zio" %% "zio-test" % zioVersion % Test,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object Client {
roleSelectionOnEngineer: SelectionBuilder[Engineer, RoleSelection],
roleSelectionOnMechanic: SelectionBuilder[Mechanic, RoleSelection],
roleSelectionOnPilot: SelectionBuilder[Pilot, RoleSelection]
): ViewSelection[RoleSelection] = (name ~ nicknames ~ origin ~ role(
): ViewSelection[RoleSelection] = (name ~ nicknames ~ origin ~ role(
roleSelectionOnCaptain,
roleSelectionOnEngineer,
roleSelectionOnMechanic,
Expand All @@ -72,7 +72,7 @@ object Client {
onEngineer: SelectionBuilder[Engineer, A],
onMechanic: SelectionBuilder[Mechanic, A],
onPilot: SelectionBuilder[Pilot, A]
): SelectionBuilder[Character, Option[A]] = Field(
): SelectionBuilder[Character, Option[A]] = Field(
"role",
OptionOf(
ChoiceOf(
Expand Down Expand Up @@ -131,7 +131,7 @@ object Client {
*/
def characters[A](
origin: Option[Origin] = None
)(innerSelection: SelectionBuilder[Character, A]): SelectionBuilder[RootQuery, List[A]] =
)(innerSelection: SelectionBuilder[Character, A]): SelectionBuilder[RootQuery, List[A]] =
Field("characters", ListOf(Obj(innerSelection)), arguments = List(Argument("origin", origin, "Origin")))
@deprecated("Use `characters`", "")
def character[A](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ object IntrospectionClient {
def description: SelectionBuilder[__Type, Option[String]] = Field("description", OptionOf(Scalar()))
def fields[A](
includeDeprecated: Option[Boolean] = None
)(innerSelection: SelectionBuilder[__Field, A]): SelectionBuilder[__Type, Option[List[A]]] =
)(innerSelection: SelectionBuilder[__Field, A]): SelectionBuilder[__Type, Option[List[A]]] =
Field(
"fields",
OptionOf(ListOf(Obj(innerSelection))),
Expand All @@ -140,7 +140,7 @@ object IntrospectionClient {
Field("possibleTypes", OptionOf(ListOf(Obj(innerSelection))))
def enumValues[A](
includeDeprecated: Option[Boolean] = None
)(innerSelection: SelectionBuilder[__EnumValue, A]): SelectionBuilder[__Type, Option[List[A]]] =
)(innerSelection: SelectionBuilder[__EnumValue, A]): SelectionBuilder[__Type, Option[List[A]]] =
Field(
"enumValues",
OptionOf(ListOf(Obj(innerSelection))),
Expand Down
24 changes: 12 additions & 12 deletions client/src/main/scala/caliban/client/SelectionBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ sealed trait SelectionBuilder[-Origin, +A] { self =>
/**
* Maps a tupled result to a type `Res` using a function `f` with 2 parameters
*/
def mapN[B, C, Res](f: (B, C) => Res)(implicit ev: A <:< (B, C)): SelectionBuilder[Origin, Res] =
def mapN[B, C, Res](f: (B, C) => Res)(implicit ev: A <:< (B, C)): SelectionBuilder[Origin, Res] =
self.map(ev.andThen { case (b, c) => f(b, c) })

/**
Expand All @@ -150,63 +150,63 @@ sealed trait SelectionBuilder[-Origin, +A] { self =>
*/
def mapN[B, C, D, E, Res](
f: (B, C, D, E) => Res
)(implicit ev: A <:< (((B, C), D), E)): SelectionBuilder[Origin, Res] =
)(implicit ev: A <:< (((B, C), D), E)): SelectionBuilder[Origin, Res] =
self.map(ev.andThen { case (((b, c), d), e) => f(b, c, d, e) })

/**
* Maps a tupled result to a type `Res` using a function `f` with 5 parameters
*/
def mapN[B, C, D, E, F, Res](
f: (B, C, D, E, F) => Res
)(implicit ev: A <:< ((((B, C), D), E), F)): SelectionBuilder[Origin, Res] =
)(implicit ev: A <:< ((((B, C), D), E), F)): SelectionBuilder[Origin, Res] =
self.map(ev.andThen { case ((((b, c), d), e), ff) => f(b, c, d, e, ff) })

/**
* Maps a tupled result to a type `Res` using a function `f` with 6 parameters
*/
def mapN[B, C, D, E, F, G, Res](
f: (B, C, D, E, F, G) => Res
)(implicit ev: A <:< (((((B, C), D), E), F), G)): SelectionBuilder[Origin, Res] =
)(implicit ev: A <:< (((((B, C), D), E), F), G)): SelectionBuilder[Origin, Res] =
self.map(ev.andThen { case (((((b, c), d), e), ff), g) => f(b, c, d, e, ff, g) })

/**
* Maps a tupled result to a type `Res` using a function `f` with 7 parameters
*/
def mapN[B, C, D, E, F, G, H, Res](
f: (B, C, D, E, F, G, H) => Res
)(implicit ev: A <:< ((((((B, C), D), E), F), G), H)): SelectionBuilder[Origin, Res] =
)(implicit ev: A <:< ((((((B, C), D), E), F), G), H)): SelectionBuilder[Origin, Res] =
self.map(ev.andThen { case ((((((b, c), d), e), ff), g), h) => f(b, c, d, e, ff, g, h) })

/**
* Maps a tupled result to a type `Res` using a function `f` with 8 parameters
*/
def mapN[B, C, D, E, F, G, H, I, Res](
f: (B, C, D, E, F, G, H, I) => Res
)(implicit ev: A <:< (((((((B, C), D), E), F), G), H), I)): SelectionBuilder[Origin, Res] =
)(implicit ev: A <:< (((((((B, C), D), E), F), G), H), I)): SelectionBuilder[Origin, Res] =
self.map(ev.andThen { case (((((((b, c), d), e), ff), g), h), i) => f(b, c, d, e, ff, g, h, i) })

/**
* Maps a tupled result to a type `Res` using a function `f` with 9 parameters
*/
def mapN[B, C, D, E, F, G, H, I, J, Res](
f: (B, C, D, E, F, G, H, I, J) => Res
)(implicit ev: A <:< ((((((((B, C), D), E), F), G), H), I), J)): SelectionBuilder[Origin, Res] =
)(implicit ev: A <:< ((((((((B, C), D), E), F), G), H), I), J)): SelectionBuilder[Origin, Res] =
self.map(ev.andThen { case ((((((((b, c), d), e), ff), g), h), i), j) => f(b, c, d, e, ff, g, h, i, j) })

/**
* Maps a tupled result to a type `Res` using a function `f` with 10 parameters
*/
def mapN[B, C, D, E, F, G, H, I, J, K, Res](
f: (B, C, D, E, F, G, H, I, J, K) => Res
)(implicit ev: A <:< (((((((((B, C), D), E), F), G), H), I), J), K)): SelectionBuilder[Origin, Res] =
)(implicit ev: A <:< (((((((((B, C), D), E), F), G), H), I), J), K)): SelectionBuilder[Origin, Res] =
self.map(ev.andThen { case (((((((((b, c), d), e), ff), g), h), i), j), k) => f(b, c, d, e, ff, g, h, i, j, k) })

/**
* Maps a tupled result to a type `Res` using a function `f` with 11 parameters
*/
def mapN[B, C, D, E, F, G, H, I, J, K, L, Res](
f: (B, C, D, E, F, G, H, I, J, K, L) => Res
)(implicit ev: A <:< ((((((((((B, C), D), E), F), G), H), I), J), K), L)): SelectionBuilder[Origin, Res] =
)(implicit ev: A <:< ((((((((((B, C), D), E), F), G), H), I), J), K), L)): SelectionBuilder[Origin, Res] =
self.map(ev.andThen { case ((((((((((b, c), d), e), ff), g), h), i), j), k), l) =>
f(b, c, d, e, ff, g, h, i, j, k, l)
})
Expand Down Expand Up @@ -365,7 +365,7 @@ object SelectionBuilder {
alias: Option[String] = None,
arguments: List[Argument[_]] = Nil,
directives: List[Directive] = Nil
) extends SelectionBuilder[Origin, A] { self =>
) extends SelectionBuilder[Origin, A] { self =>
override def fromGraphQL(value: __Value): Either[DecodingError, A] =
value match {
case __ObjectValue(fields) =>
Expand Down Expand Up @@ -400,7 +400,7 @@ object SelectionBuilder {
override def withAlias(alias: String): SelectionBuilder[Origin, (A, B)] = self // makes no sense, do nothing
}
case class Mapping[Origin, A, B](builder: SelectionBuilder[Origin, A], f: A => Either[DecodingError, B])
extends SelectionBuilder[Origin, B] {
extends SelectionBuilder[Origin, B] {
override def fromGraphQL(value: __Value): Either[DecodingError, B] = builder.fromGraphQL(value).flatMap(f)

override def withDirective(directive: Directive): SelectionBuilder[Origin, B] =
Expand All @@ -410,7 +410,7 @@ object SelectionBuilder {

override def withAlias(alias: String): SelectionBuilder[Origin, B] = Mapping(builder.withAlias(alias), f)
}
case class Pure[A](a: A) extends SelectionBuilder[Any, A] { self =>
case class Pure[A](a: A) extends SelectionBuilder[Any, A] { self =>
override private[caliban] def toSelectionSet = Nil

override private[caliban] def fromGraphQL(value: __Value) = Right(a)
Expand Down
2 changes: 1 addition & 1 deletion client/src/test/scala/caliban/client/TestData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object TestData {
onPilot: SelectionBuilder[Pilot, A],
onMechanic: SelectionBuilder[Mechanic, A],
onEngineer: SelectionBuilder[Engineer, A]
): SelectionBuilder[Character, Option[A]] =
): SelectionBuilder[Character, Option[A]] =
Field(
"role",
OptionOf(
Expand Down
10 changes: 5 additions & 5 deletions codegen-sbt/src/main/scala/caliban/codegen/CalibanPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ object CalibanPlugin extends AutoPlugin {
import autoImport._

lazy val baseSettings = Seq(
caliban := (caliban / calibanGenerator).value,
(caliban / sourceManaged) := {
caliban := (caliban / calibanGenerator).value,
(caliban / sourceManaged) := {
sourceManaged.value / "caliban-codegen-sbt"
},
(caliban / calibanSources) := {
if (Seq(Compile, Test).contains(configuration.value)) sourceDirectory.value / "graphql"
else sourceDirectory.value / "main" / "graphql"
},
caliban / calibanSettings := Seq.empty
caliban / calibanSettings := Seq.empty
)

lazy val calibanScopedSettings = inTask(caliban)(
Seq(
sources := (calibanSources.value ** "*.graphql").get.sorted,
clean := {
sources := (calibanSources.value ** "*.graphql").get.sorted,
clean := {
val sourceDir = sourceManaged.value
IO.delete((sourceDir ** "*").get)
IO.createDirectory(sourceDir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ object CalibanSourceGenerator {

CalibanFileSettings(
file = source,
settings = fileSettings
.collect({ case needle if source.toPath.endsWith(needle.file.toPath) => needle })
settings = fileSettings.collect { case needle if source.toPath.endsWith(needle.file.toPath) => needle }
.foldLeft[CalibanCommonSettings](defaults) { case (acc, next) => acc.combine(next.settings) }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ object CompileTimeCalibanClientPlugin extends AutoPlugin {
private lazy val pluginSettings =
inTask(ctCalibanClient)(
Seq(
ctCalibanClientsSettings := Seq.empty,
ctCalibanClientsSettings := Seq.empty,
ctCalibanClientsVersionedCode := true,
ctCalibanClientGenerate := {
ctCalibanClientGenerate := {
// That helped: https://stackoverflow.com/q/26244115/2431728
Def.taskDyn {
import Functions._
Expand Down
Loading

0 comments on commit 1311119

Please sign in to comment.