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 scalafmt to 3.8.1 #2216

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
version = "3.1.2"

version = "3.8.1"
runner.dialect = scala213
maxColumn = 120
align.preset = most
Expand All @@ -22,3 +21,8 @@ fileOverride {
runner.dialect = scala3
}
}

project.excludePaths = [
"glob:**/target/**"
"glob:**/resources/**"
]
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,8 @@ lazy val apiMappingSettings = Def.settings(
apiMappings ++= {
val depsByModule = (Compile / dependencyClasspathAsJars).value.flatMap { dep =>
dep.get(moduleID.key).map((_, dep.data))
}.groupBy { case (moduleID, _) => (moduleID.organization, moduleID.name) }.mapValues(_.head)
}.groupBy { case (moduleID, _) => (moduleID.organization, moduleID.name) }
.mapValues(_.head)

val cross = CrossVersion(crossVersion.value, scalaVersion.value, scalaBinaryVersion.value)
.getOrElse((s: String) => s)
Expand Down
10 changes: 5 additions & 5 deletions client/src/main/scala/caliban/client/GraphQLResponseError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ case class GraphQLResponseError(
*/
def render(includeExtensions: Boolean): String =
s"${message} ${locations.getOrElse(Nil).map(loc => s"at line ${loc.line} and column ${loc.column}").mkString(" ")}${path.fold("")(p =>
s" at path ${p.map {
case Left(value) => s"/$value"
case Right(value) => s"[$value]"
}.mkString("")}"
)}${if (includeExtensions) extensions.fold("")(ext => s" Extensions: $ext") else ""}"
s" at path ${p.map {
case Left(value) => s"/$value"
case Right(value) => s"[$value]"
}.mkString("")}"
)}${if (includeExtensions) extensions.fold("")(ext => s" Extensions: $ext") else ""}"
}

object GraphQLResponseError {
Expand Down
17 changes: 9 additions & 8 deletions client/src/main/scala/caliban/client/SelectionBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,16 @@ sealed trait SelectionBuilder[-Origin, +A] { self =>
*/
def decode(payload: String): Either[CalibanClientError, (A, List[GraphQLResponseError], Option[__ObjectValue])] =
for {
parsed <- try Right(
readFromString[GraphQLResponse](
payload,
// allow parsing of large payloads
ReaderConfig
.withMaxBufSize(max(payload.length, ReaderConfig.maxBufSize))
.withMaxCharBufSize(max(payload.length, ReaderConfig.maxCharBufSize))
parsed <- try
Right(
readFromString[GraphQLResponse](
payload,
// allow parsing of large payloads
ReaderConfig
.withMaxBufSize(max(payload.length, ReaderConfig.maxBufSize))
.withMaxCharBufSize(max(payload.length, ReaderConfig.maxCharBufSize))
)
)
)
catch {
case NonFatal(ex) => Left(DecodingError("Json deserialization error", Some(ex)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ object Version {
sys.props.get("plugin.version") match {
case Some(x) => x
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}}
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ object Version {
sys.props.get("plugin.version") match {
case Some(x) => x
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}}
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("com.github.ghostdogpr" % "caliban-codegen-sbt" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is also quite bad for readability :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my experience, fixing the "ugly" cases like this is best done manually. For instance

  case _ => 
    val msg = """..."""
    sys.error(msg)

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import poc.caliban.client.generated.potatoes._
import sttp.capabilities.WebSockets
import sttp.capabilities.zio.ZioStreams
import sttp.client3.SttpBackend
import zio.{Task, ZIO}
import zio.{ Task, ZIO }

trait PotatoesClient {
def eradicate(name: String): Task[Unit]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ trait PostService {
}

object PostService {
def findById(id: PostId) = ZIO.serviceWithZIO[PostService](_.findById(id))
def findById(id: PostId) = ZIO.serviceWithZIO[PostService](_.findById(id))
def createPost(author: AuthorName, title: PostTitle, content: PostContent) =
ZIO.serviceWithZIO[PostService](_.createPost(author, title, content))
def deletePost(id: PostId) = ZIO.serviceWithZIO[PostService](_.deletePost(id))
def all = ZStream.serviceWithStream[PostService](_.all)
def deletePost(id: PostId) = ZIO.serviceWithZIO[PostService](_.deletePost(id))
def all = ZStream.serviceWithStream[PostService](_.all)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object Resolvers {
private val queries =
Query(
byName = name => PotatoesService.findByName(name),
byColor = color => PotatoesService.findByColor(color),
byColor = color => PotatoesService.findByColor(color)
)

private val mutations =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ trait PotatoesService {
}

object PotatoesService {
def findByName(name: Potato.Name) = ZIO.serviceWithZIO[PotatoesService](_.findByName(name))
def findByColor(color: Potato.Color) = ZIO.serviceWithZIO[PotatoesService](_.findByColor(color))
def findByName(name: Potato.Name) = ZIO.serviceWithZIO[PotatoesService](_.findByName(name))
def findByColor(color: Potato.Color) = ZIO.serviceWithZIO[PotatoesService](_.findByColor(color))
def makeNewSpecies(name: Potato.Name, color: Potato.Color) =
ZIO.serviceWithZIO[PotatoesService](_.makeNewSpecies(name, color))
def eradicate(name: Potato.Name) = ZIO.serviceWithZIO[PotatoesService](_.eradicate(name))
def all = ZStream.serviceWithStream[PotatoesService](_.all)
def eradicate(name: Potato.Name) = ZIO.serviceWithZIO[PotatoesService](_.eradicate(name))
def all = ZStream.serviceWithStream[PotatoesService](_.all)
}
6 changes: 2 additions & 4 deletions core/src/main/scala/caliban/execution/Executor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,14 @@ object Executor {
def reduceField(f: Field): (String, ReducedStep[R], FieldInfo) = {
val aliasedName = f.aliasedName
val fname = f.name
val field = {
val field =
if (fname == "__typename") PureStep(StringValue(objectName))
else reduceStep(getFieldStep(fname), f, f.arguments, PathValue.Key(aliasedName) :: path)
}
(aliasedName, field, fieldInfo(f, aliasedName, path, f.directives))
}

val filteredFields = mergeFields(currentField, objectName)
val (deferred, eager) = {
val (deferred, eager) =
if (isDeferredEnabled) {
filteredFields.partitionMap { f =>
val entry = reduceField(f)
Expand All @@ -163,7 +162,6 @@ object Executor {
}
}
} else (Nil, filteredFields.map(reduceField))
}

val eagerReduced = reduceObject(eager)
deferred match {
Expand Down
10 changes: 6 additions & 4 deletions core/src/main/scala/caliban/interop/jsoniter/jsoniter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,12 @@ private[caliban] object ValueJsoniter {
var digits = 0
var b = in.nextByte()
if (b == '-') b = in.nextByte()
try while (b >= '0' && b <= '9') {
b = in.nextByte()
digits += 1
} catch {
try
while (b >= '0' && b <= '9') {
b = in.nextByte()
digits += 1
}
catch {
case _: JsonReaderException => // ignore the end of input error for now
}
in.rollbackToMark()
Expand Down
10 changes: 6 additions & 4 deletions core/src/main/scala/caliban/parsing/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ object Parser {
*/
def parseQueryEither(query: String): Either[ParsingError, Document] = {
val sm = SourceMapper(query)
try parse(query, document(_)) match {
case Parsed.Success(value, _) => Right(Document(value.definitions, sm))
case f: Parsed.Failure => Left(ParsingError(f.msg, Some(sm.getLocation(f.index))))
} catch {
try
parse(query, document(_)) match {
case Parsed.Success(value, _) => Right(Document(value.definitions, sm))
case f: Parsed.Failure => Left(ParsingError(f.msg, Some(sm.getLocation(f.index))))
}
catch {
case NonFatal(ex) => Left(ParsingError(s"Internal parsing error", innerThrowable = Some(ex)))
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/caliban/parsing/VariablesCoercer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ object VariablesCoercer {
context: => String // Careful not to materialize unless we need to fail!
): EReader[Any, ValidationError, InputValue] =
typ.kind match {
case __TypeKind.NON_NULL =>
case __TypeKind.NON_NULL =>
value match {
case NullValue =>
failValidation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import scala.annotation.nowarn
private[caliban] trait SelectionParsers extends ValueParsers {

@deprecated("Kept for bincompat only, scheduled to be removed")
def alias(implicit ev: P[Any]): P[String] = name ~ ":"
def alias(implicit ev: P[Any]): P[String] = name ~ ":"
def aliasOrName(implicit ev: P[Any]): P[String] = ":" ~/ name

def argument(implicit ev: P[Any]): P[(String, InputValue)] = name ~ ":" ~ value
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/scala/caliban/transformers/Transformer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,9 @@ object Transformer {
private def shouldKeep(typeName: String, fieldName: String): Boolean =
!map.getOrElse(typeName, Set.empty).contains(fieldName)

val typeVisitor: TypeVisitor = {
val typeVisitor: TypeVisitor =
TypeVisitor.fields.filterWith((t, field) => shouldKeep(t.name.getOrElse(""), field.name)) |+|
TypeVisitor.inputFields.filterWith((t, field) => shouldKeep(t.name.getOrElse(""), field.name))
}

protected val typeNames: Set[String] = map.keySet

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object FragmentValidator {
if (doTypesConflict(f1.fieldDef._type, f2.fieldDef._type)) {
Chunk(
s"$name has conflicting types: ${f1.parentType.name.getOrElse("")}.${f1.fieldDef.name} and ${f2.parentType.name
.getOrElse("")}.${f2.fieldDef.name}. Try using an alias."
.getOrElse("")}.${f2.fieldDef.name}. Try using an alias."
)
} else
sameResponseShapeByName(f1.selection.selectionSet ::: f2.selection.selectionSet)
Expand Down
17 changes: 8 additions & 9 deletions core/src/main/scala/caliban/validation/Validator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ object Validator {
if (applicableTypes.isEmpty)
failValidation(
s"${name.fold("Inline fragment spread")(n => s"Fragment spread '$n'")} is not possible: possible types are '${possibleTypes
.mkString(", ")}' and possible fragment types are '${possibleFragmentTypes.mkString(", ")}'.",
.mkString(", ")}' and possible fragment types are '${possibleFragmentTypes.mkString(", ")}'.",
"Fragments are declared on a type and will only apply when the runtime object type matches the type condition. They also are spread within the context of a parent type. A fragment spread is only valid if its type condition could ever apply within the parent type."
)
else validateFields(context, selectionSet, fragmentType)
Expand Down Expand Up @@ -568,13 +568,13 @@ object Validator {
case (None, None) | (None, Some(NullValue)) =>
failValidation(
s"Required argument '${arg.name}' is null or missing on field '${field.name}' of type '${currentType.name
.getOrElse("")}'.",
.getOrElse("")}'.",
"Arguments can be required. An argument is required if the argument type is non‐null and does not have a default value. Otherwise, the argument is optional."
)
case (Some(_), Some(NullValue)) =>
failValidation(
s"Required argument '${arg.name}' is null on '${field.name}' of type '${currentType.name
.getOrElse("")}'.",
.getOrElse("")}'.",
"Arguments can be required. An argument is required if the argument type is non‐null and does not have a default value. Otherwise, the argument is optional."
)
case _ => zunit
Expand Down Expand Up @@ -714,7 +714,7 @@ object Validator {
case Type.NamedType(name, _) =>
failWhen(!locationType.name.contains(name))(
s"Variable '$variableName' usage is not allowed because its type doesn't match the schema ($name instead of ${locationType.name
.getOrElse("")}).",
.getOrElse("")}).",
explanation
)
}
Expand Down Expand Up @@ -785,7 +785,7 @@ object Validator {

lazy val validateSubscriptionOperation: QueryValidation = ZPure.environmentWithPure { env =>
val context = env.get[Context]
val error = {
val error =
for {
t <- context.rootType.subscriptionType
op <- context.operations.find(_.operationType == OperationType.Subscription)
Expand Down Expand Up @@ -820,7 +820,6 @@ object Validator {
)
}
} yield error
}
ZPure.fromOption(error).flip
}

Expand Down Expand Up @@ -1162,9 +1161,9 @@ object Validator {
case Some((name, values)) =>
failValidation(
s"Type '$name' is defined multiple times (${values
.sortBy(v => v.origin.getOrElse(""))
.map(v => s"${v.kind}${v.origin.fold("")(a => s" in $a")}")
.mkString(", ")}).",
.sortBy(v => v.origin.getOrElse(""))
.map(v => s"${v.kind}${v.origin.fold("")(a => s" in $a")}")
.mkString(", ")}).",
"Each type must be defined only once."
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ object Scala3DerivesSpec extends ZIOSpecDefault {
sealed trait Foo derives Schema.SemiAuto {
val i: Instant
}
object Foo {
object Foo {
final case class FooA(i: Instant, s1: String) extends Foo derives Schema.SemiAuto, ArgBuilder
final case class FooB(i: Instant, i1: Int) extends Foo derives Schema.SemiAuto, ArgBuilder
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/scala/caliban/TestUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object TestUtils {
case object MARS extends Origin
case object BELT extends Origin
@GQLDeprecated("Use: EARTH | MARS | BELT")
case object MOON extends Origin
case object MOON extends Origin
}

@GQLDirective(Directive("uniondirective"))
Expand Down Expand Up @@ -393,7 +393,7 @@ object TestUtils {
sealed trait FieldInterface {
val a: String
}
object FieldInterface {
object FieldInterface {
case class FieldObject(a: String, b: Int) extends FieldInterface
}
case class TestFieldObject(fieldInterface: FieldObject)
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/scala/caliban/execution/ExecutionSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object ExecutionSpec extends ZIOSpecDefault {
def id: String
def name: String
}
object Base {
object Base {
@GQLName("BaseOne")
case class One(
id: String,
Expand Down Expand Up @@ -885,7 +885,7 @@ object ExecutionSpec extends ZIOSpecDefault {
def id: String
def name: String
}
object Character {
object Character {
case class Human(
id: String,
name: String,
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/scala/caliban/schema/OptionalSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object OptionalSpec extends ZIOSpecDefault {
implicit def wrapperSchema[A](implicit ev: Schema[Any, A]): Schema[Any, Wrapper[A]] =
new Schema[Any, Wrapper[A]] {
@annotation.nowarn
override def optional = ev.optional
override def optional = ev.optional
def toType(isInput: Boolean, isSubscription: Boolean) = ev.toType_(isInput, isSubscription)
def resolve(value: Wrapper[A]): Step[Any] =
ev.resolve(value.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ object i2076 {

@GQLName("WidgetAChild")
case class Child(name: String, foo: String, bar: String)
object Child {
object Child {
implicit val schema: Schema[Any, Child] = Schema.gen
}
}
Expand All @@ -596,7 +596,7 @@ object i2076 {

@GQLName("WidgetBChild")
case class Child(name: String, foo: String)
object Child {
object Child {
implicit val schema: Schema[Any, Child] = Schema.gen
}
}
Expand Down
Loading