Skip to content

Commit

Permalink
Scalafmt 2.5.1 (#257)
Browse files Browse the repository at this point in the history
Co-authored-by: Julien Jean Paul Sirocchi <[email protected]>
  • Loading branch information
barambani and sirocchj authored May 5, 2020
1 parent 7b55c16 commit 5f37295
Show file tree
Hide file tree
Showing 25 changed files with 343 additions and 300 deletions.
9 changes: 5 additions & 4 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version=2.4.2
version=2.5.1

align = more # For pretty alignment.
align.preset = more # For pretty alignment.
maxColumn = 140 # For my wide 30" display.

rewrite.sortModifiers.order = [
Expand All @@ -22,6 +22,8 @@ rewrite.rules = [
PreferCurlyFors
]

spaces.inByNameTypes = false

rewrite.redundantBraces.stringInterpolation = true
rewrite.redundantBraces.includeUnitMethods = true

Expand All @@ -30,5 +32,4 @@ newlines.neverInResultType = true
newlines.alwaysBeforeMultilineDef = true
newlines.sometimesBeforeColonInMethodReturnType = false
newlines.penalizeSingleSelectMultiArgList = false
newlines.afterImplicitKWInVerticalMultiline = true
newlines.beforeImplicitKWInVerticalMultiline = true
newlines.implicitParamListModifierPrefer = before
40 changes: 20 additions & 20 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ val V = new {
val shapeless = "2.3.3"
}

val `cats-core` = Def.setting("org.typelevel" %% "cats-core" % V.cats)
val `cats-laws` = Def.setting("org.typelevel" %% "cats-laws" % V.cats)
val `circe-core` = Def.setting("io.circe" %%% "circe-core" % V.circe)
val `circe-parser` = Def.setting("io.circe" %%% "circe-parser" % V.circe)
val `fs2-core` = Def.setting("co.fs2" %%% "fs2-core" % V.fs2)
val `fs2-io` = Def.setting("co.fs2" %% "fs2-io" % V.fs2)
val kittens = Def.setting("org.typelevel" %%% "kittens" % V.kittens)
val `log-effect-fs2` = Def.setting("io.laserdisc" %%% "log-effect-fs2" % V.`log-effect-fs2`)
val refined = Def.setting("eu.timepit" %%% "refined" % V.refined)
val `scodec-bits` = Def.setting("org.scodec" %%% "scodec-bits" % V.`scodec-bits`)
val `scodec-core` = Def.setting("org.scodec" %%% "scodec-core" % V.`scodec-core`)
val `scodec-stream` = Def.setting("org.scodec" %%% "scodec-stream" % V.`scodec-stream`)
val shapeless = Def.setting("com.chuusai" %%% "shapeless" % V.shapeless)
val `cats-core` = Def.setting("org.typelevel" %% "cats-core" % V.cats)
val `cats-laws` = Def.setting("org.typelevel" %% "cats-laws" % V.cats)
val `circe-core` = Def.setting("io.circe" %%% "circe-core" % V.circe)
val `circe-parser` = Def.setting("io.circe" %%% "circe-parser" % V.circe)
val `fs2-core` = Def.setting("co.fs2" %%% "fs2-core" % V.fs2)
val `fs2-io` = Def.setting("co.fs2" %% "fs2-io" % V.fs2)
val kittens = Def.setting("org.typelevel" %%% "kittens" % V.kittens)
val `log-effect-fs2` = Def.setting("io.laserdisc" %%% "log-effect-fs2" % V.`log-effect-fs2`)
val refined = Def.setting("eu.timepit" %%% "refined" % V.refined)
val `scodec-bits` = Def.setting("org.scodec" %%% "scodec-bits" % V.`scodec-bits`)
val `scodec-core` = Def.setting("org.scodec" %%% "scodec-core" % V.`scodec-core`)
val `scodec-stream` = Def.setting("org.scodec" %%% "scodec-stream" % V.`scodec-stream`)
val shapeless = Def.setting("com.chuusai" %%% "shapeless" % V.shapeless)

val `cats-discipline` = Def.setting("org.typelevel" %% "discipline-core" % V.`cats-discipline` % Test)
val `discipline-scalatest` = Def.setting("org.typelevel" %% "discipline-scalatest" % V.`discipline-scalatest` % Test)
val `circe-generic` = Def.setting("io.circe" %%% "circe-generic" % V.circe % Test)
val `refined-scalacheck` = Def.setting("eu.timepit" %%% "refined-scalacheck" % V.refined % Test)
val scalacheck = Def.setting("org.scalacheck" %%% "scalacheck" % V.scalacheck % Test)
val scalatest = Def.setting("org.scalatest" %%% "scalatest" % V.scalatest % Test)
val `scalatest-plus` = Def.setting("org.scalatestplus" %%% "scalacheck-1-14" % V.`scalatest-plus` % Test)
val `cats-discipline` = Def.setting("org.typelevel" %% "discipline-core" % V.`cats-discipline` % Test)
val `discipline-scalatest` = Def.setting("org.typelevel" %% "discipline-scalatest" % V.`discipline-scalatest` % Test)
val `circe-generic` = Def.setting("io.circe" %%% "circe-generic" % V.circe % Test)
val `refined-scalacheck` = Def.setting("eu.timepit" %%% "refined-scalacheck" % V.refined % Test)
val scalacheck = Def.setting("org.scalacheck" %%% "scalacheck" % V.scalacheck % Test)
val scalatest = Def.setting("org.scalatest" %%% "scalatest" % V.scalatest % Test)
val `scalatest-plus` = Def.setting("org.scalatestplus" %%% "scalacheck-1-14" % V.`scalatest-plus` % Test)

val `scala-parallel-collections` = Def.setting {
CrossVersion.partialVersion(scalaVersion.value) match {
Expand Down
7 changes: 4 additions & 3 deletions circe/src/main/scala/laserdisc/interop/circe.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import io.circe.syntax._

object circe {
implicit final def encoderShow[A: Encoder]: Show[A] = Show.instance(_.asJson.noSpaces)
implicit final def decoderRead[A: Decoder]: Bulk ==> A = Read.instance {
case Bulk(s) => parser.decode(s).leftMap(err => RESPDecErr(err.show))
}
implicit final def decoderRead[A: Decoder]: Bulk ==> A =
Read.instance {
case Bulk(s) => parser.decode(s).leftMap(err => RESPDecErr(err.show))
}
}
4 changes: 3 additions & 1 deletion circe/src/test/scala/laserdisc/interop/CirceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ final class CirceSpec extends AnyWordSpec with Matchers with ScalaCheckPropertyC

"handling a json that does not respect the contract" should {
"fail to decode" in {
Read[Bulk, Bar].read(Bulk("""{"i": null}""")) onLeft (_.message shouldBe "DecodingFailure at .x: Attempt to decode value on failed cursor")
Read[Bulk, Bar].read(
Bulk("""{"i": null}""")
) onLeft (_.message shouldBe "DecodingFailure at .x: Attempt to decode value on failed cursor")
}
}
}
Expand Down
25 changes: 13 additions & 12 deletions cli/src/main/scala/laserdisc/cli/CLI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,20 @@ object CLI extends IOApp { self =>
| ````....````
|""".stripMargin

override final def run(args: List[String]): IO[ExitCode] = args match {
case arg1 :: arg2 :: Nil =>
val maybeHost = Host.from(arg1).toOption
val maybePort = Either.catchNonFatal(arg2.toInt).flatMap(Port.from).toOption

(maybeHost, maybePort) match {
case (Some(ip), Some(port)) =>
IO(println(logo)) >> impl.mkStream(ip, port)(SyncLogWriter.noOpLog[IO]).compile.drain.as(ExitCode.Success)
case _ => IO(println("please supply valid host and port (space separated)")).as(ExitCode.Error)
}
override final def run(args: List[String]): IO[ExitCode] =
args match {
case arg1 :: arg2 :: Nil =>
val maybeHost = Host.from(arg1).toOption
val maybePort = Either.catchNonFatal(arg2.toInt).flatMap(Port.from).toOption

(maybeHost, maybePort) match {
case (Some(ip), Some(port)) =>
IO(println(logo)) >> impl.mkStream(ip, port)(SyncLogWriter.noOpLog[IO]).compile.drain.as(ExitCode.Success)
case _ => IO(println("please supply valid host and port (space separated)")).as(ExitCode.Error)
}

case _ => IO(println("please supply host and port (space separated)")).as(ExitCode.Error)
}
case _ => IO(println("please supply host and port (space separated)")).as(ExitCode.Error)
}

private[cli] final object impl {
private[this] val tb = universe.runtimeMirror(self.getClass.getClassLoader).mkToolBox()
Expand Down
20 changes: 8 additions & 12 deletions core/src/main/scala/laserdisc/laserdisc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -185,25 +185,21 @@ package object laserdisc {

private[laserdisc] final object ToInt {
def unapply(l: Long): Option[Int] =
try {
Some(j.Math.toIntExact(l))
} catch { case _: ArithmeticException => None }
try Some(j.Math.toIntExact(l))
catch { case _: ArithmeticException => None }
def unapply(s: String): Option[Int] =
try {
Some(j.Integer.parseInt(s))
} catch { case _: NumberFormatException => None }
try Some(j.Integer.parseInt(s))
catch { case _: NumberFormatException => None }
}
private[laserdisc] final object ToLong {
def unapply(s: String): Option[Long] =
try {
Some(j.Long.parseLong(s))
} catch { case _: NumberFormatException => None }
try Some(j.Long.parseLong(s))
catch { case _: NumberFormatException => None }
}
private[laserdisc] final object ToDouble {
def unapply(s: String): Option[Double] =
try {
Some(j.Double.parseDouble(s))
} catch { case _: NumberFormatException => None }
try Some(j.Double.parseDouble(s))
catch { case _: NumberFormatException => None }
}

private[laserdisc] implicit final class WidenOps1[F[_], A](private val fa: F[A]) extends AnyVal {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/laserdisc/protocol/ClusterP.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ object ClusterP {
val errorS = "String ==> Node, Error decoding a cluster Node. Error was: "
_.split(SPACE_CH).toList match {
case NodeId(id) :: A(Right(a)) :: Fs(Right(fs)) :: MM(Right(mm)) :: ToInt(NonNegInt(ps)) :: ToInt(NonNegInt(pr)) ::
ToInt(NonNegInt(ce)) :: L(Right(l)) :: Ss(Right(ss)) =>
ToInt(NonNegInt(ce)) :: L(Right(l)) :: Ss(Right(ss)) =>
Right(Node(id, a, fs, mm, ps, pr, ce, l, ss))
case _ :: A(Left(e)) :: _ :: _ :: _ :: _ :: _ :: _ :: _ => Left(RESPDecErr(s"$errorS $e"))
case _ :: _ :: Fs(Left(e)) :: _ :: _ :: _ :: _ :: _ :: _ => Left(RESPDecErr(s"$errorS $e"))
Expand Down
9 changes: 5 additions & 4 deletions core/src/main/scala/laserdisc/protocol/EitherSyntax.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ private[protocol] final class EitherValuesSyntaxOps[A](private val a: A) extends
}

private[protocol] final class EitherSyntaxOps[A, B](private val aOrB: A | B) extends AnyVal {
def leftMap[C](f: A => C): C | B = aOrB match {
case Left(a) => Left(f(a))
case right => right.coerceLeft[C, |]
}
def leftMap[C](f: A => C): C | B =
aOrB match {
case Left(a) => Left(f(a))
case right => right.coerceLeft[C, |]
}
}
6 changes: 3 additions & 3 deletions core/src/main/scala/laserdisc/protocol/GeoP.scala
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ object GeoP {
}
implicit final val radiusModeCoordinatesAndDistanceRead: Arr ==> RadiusMode.coordinatesAndDistance.Res = Read.instance {
case Arr(
Bulk(Key(k)) +: Bulk(ToDouble(NonNegDouble(d))) +:
Bulk(Key(k)) +: Bulk(ToDouble(NonNegDouble(d))) +:
Arr(Bulk(ToDouble(Longitude(long))) +: Bulk(ToDouble(Latitude(lat))) +: Seq()) +: Seq()
) =>
Right(KeyCoordinatesAndDistance(k, Coordinates(lat, long), d))
Expand All @@ -124,7 +124,7 @@ object GeoP {
}
implicit final val radiusModeCoordinatesAndHashRead: Arr ==> RadiusMode.coordinatesAndHash.Res = Read.instance {
case Arr(
Bulk(Key(k)) +: Num(NonNegLong(l)) +:
Bulk(Key(k)) +: Num(NonNegLong(l)) +:
Arr(Bulk(ToDouble(Longitude(long))) +: Bulk(ToDouble(Latitude(lat))) +: Seq()) +: Seq()
) =>
Right(KeyCoordinatesAndHash(k, Coordinates(lat, long), l))
Expand All @@ -137,7 +137,7 @@ object GeoP {
}
implicit final val radiusModeAllRead: Arr ==> RadiusMode.all.Res = Read.instance {
case Arr(
Bulk(Key(k)) +: Bulk(ToDouble(NonNegDouble(d))) +: Num(NonNegLong(l)) +:
Bulk(Key(k)) +: Bulk(ToDouble(NonNegDouble(d))) +: Num(NonNegLong(l)) +:
Arr(Bulk(ToDouble(Longitude(long))) +: Bulk(ToDouble(Latitude(lat))) +: Seq()) +: Seq()
) =>
Right(KeyCoordinatesDistanceAndHash(k, Coordinates(lat, long), d, l))
Expand Down
31 changes: 17 additions & 14 deletions core/src/main/scala/laserdisc/protocol/Protocol.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ sealed trait Protocol extends Request with Response { self =>
final def encode: RESP = codec.encode(this)
final def decode(resp: RESP): Maybe[A] = codec.decode(resp)

final def map[B](f: A => B): Protocol.Aux[B] = new Protocol {
override type A = B
override def codec: ProtocolCodec[B] = new ProtocolCodec[B] {
override def encode(protocol: Protocol): RESP = self.codec.encode(protocol)
override def decode(resp: RESP): Maybe[B] = self.codec.decode(resp).map(f(_))
final def map[B](f: A => B): Protocol.Aux[B] =
new Protocol {
override type A = B
override def codec: ProtocolCodec[B] =
new ProtocolCodec[B] {
override def encode(protocol: Protocol): RESP = self.codec.encode(protocol)
override def decode(resp: RESP): Maybe[B] = self.codec.decode(resp).map(f(_))
}
override def command: String = self.command
override def parameters: Seq[GenBulk] = self.parameters
}
override def command: String = self.command
override def parameters: Seq[GenBulk] = self.parameters
}

override final def toString: String = s"Protocol($command)"
}
Expand Down Expand Up @@ -65,12 +67,13 @@ object Protocol {
* @return A fully-fledged [[Protocol]] for the provided [[Request]]/[[Response]]
* pair
*/
final def asC[A, B](implicit R: RESPRead.Aux[A, B]): Protocol.Aux[B] = new Protocol {
override final type A = B
override final val codec: ProtocolCodec[B] = new RESPProtocolCodec(R)
override final val command: String = self.command
override final val parameters: Seq[GenBulk] = RESPParamWrite[L].write(l)
}
final def asC[A, B](implicit R: RESPRead.Aux[A, B]): Protocol.Aux[B] =
new Protocol {
override final type A = B
override final val codec: ProtocolCodec[B] = new RESPProtocolCodec(R)
override final val command: String = self.command
override final val parameters: Seq[GenBulk] = RESPParamWrite[L].write(l)
}

final def as[A, B](implicit ev: A <:!< Coproduct, R: RESPRead.Aux[A :+: CNil, B]): Protocol.Aux[B] = asC(R)

Expand Down
Loading

0 comments on commit 5f37295

Please sign in to comment.