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

Add source:future / better-monaidic-for for irrefutable pattern in for comprehension #2069

Merged
merged 1 commit into from
Jul 27, 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
16 changes: 6 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,13 @@ lazy val compilerFlags = Seq(
// Test / scalacOptions --= Seq(
// "-Xfatal-warnings"
// ),
scalacOptions ++= (if (tlIsScala3.value) Seq.empty
scalacOptions ++= (if (tlIsScala3.value)
// Handle irrefutable patterns in for comprehensions
Seq("-source:future", "-language:adhocExtensions")
else
Seq(
"-Xsource:3"
))
// scalacOptions ++= Seq(
// "-source:future" // Allow irrefutable patterns in for comprehension without withFilter
// ).filter(_ => tlIsScala3.value)
)

lazy val buildSettings = Seq(
Expand Down Expand Up @@ -138,10 +137,8 @@ lazy val commonSettings =

// Kind Projector (Scala 2 only)
libraryDependencies ++= Seq(
compilerPlugin("org.typelevel" %% "kind-projector" % "0.13.3" cross CrossVersion.full)
// Enable this once we can enable "-source:future" on Scala 3
// (We need "-source:future" for for comprehension irrefutable pattern on Scala 3)
// compilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"),
compilerPlugin("org.typelevel" %% "kind-projector" % "0.13.3" cross CrossVersion.full),
compilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1")
).filterNot(_ => tlIsScala3.value),

// MUnit
Expand Down Expand Up @@ -398,8 +395,7 @@ lazy val h2 = project
.settings(
name := "doobie-h2",
description := "H2 support for doobie.",
libraryDependencies += "com.h2database" % "h2" % h2Version,
scalacOptions -= "-Xfatal-warnings" // we need to do deprecated things
libraryDependencies += "com.h2database" % "h2" % h2Version
)

lazy val `h2-circe` = project
Expand Down
1 change: 0 additions & 1 deletion modules/bench/src/main/scala/doobie/bench/select.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class bench {
import cats.effect.unsafe.implicits.global

// Baseline hand-written JDBC code
@SuppressWarnings(Array("org.wartremover.warts.NonUnitStatements", "org.wartremover.warts.While"))
def jdbcBench(n: Int): Int = {
Class.forName("org.postgresql.Driver")
val co = DriverManager.getConnection("jdbc:postgresql:world", "postgres", "password")
Expand Down
6 changes: 0 additions & 6 deletions modules/core/src/main/scala/doobie/hi/resultset.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ object resultset {
* standard library collection via `CanBuildFrom`.
* @group Results
*/
@SuppressWarnings(Array("org.wartremover.warts.While", "org.wartremover.warts.NonUnitStatements"))
def build[F[_], A](implicit F: FactoryCompat[A, F[A]], A: Read[A]): ResultSetIO[F[A]] =
IFRS.raw { rs =>
val b = F.newBuilder
Expand All @@ -103,7 +102,6 @@ object resultset {
* CanBuildFrom not having a sensible contravariant functor instance.
* @group Results
*/
@SuppressWarnings(Array("org.wartremover.warts.While", "org.wartremover.warts.NonUnitStatements"))
def buildMap[F[_], A, B](f: A => B)(implicit F: FactoryCompat[B, F[B]], A: Read[A]): ResultSetIO[F[B]] =
IFRS.raw { rs =>
val b = F.newBuilder
Expand Down Expand Up @@ -165,10 +163,6 @@ object resultset {
* non-positive `chunkSize` yields an empty `Vector` and consumes no rows.
* @group Results
*/
@SuppressWarnings(Array(
"org.wartremover.warts.Var",
"org.wartremover.warts.While",
"org.wartremover.warts.NonUnitStatements"))
def getNextChunkV[A](chunkSize: Int)(implicit A: Read[A]): ResultSetIO[Vector[A]] =
IFRS.raw { rs =>
var n = chunkSize
Expand Down
1 change: 0 additions & 1 deletion modules/core/src/main/scala/doobie/util/analysis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ object analysis {

private val packagePrefix = "\\b[a-z]+\\.".r

@SuppressWarnings(Array("org.wartremover.warts.ToString"))
private def typeName(t: Option[String], n: NullabilityKnown): String = {
val name = packagePrefix.replaceAllIn(t.fold("«erased»")(_.toString), "")
n match {
Expand Down
10 changes: 0 additions & 10 deletions modules/core/src/main/scala/doobie/util/fragment.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ object fragment {
case Opt(a, _) => a
}.toList

@SuppressWarnings(Array("org.wartremover.warts.Var"))
val unsafeSet: (PreparedStatement, Int, elems.type) => Unit = { (ps, n, elems) =>
var index = n
elems.iterator.foreach { e =>
Expand All @@ -59,7 +58,6 @@ object fragment {
}
}

@SuppressWarnings(Array("org.wartremover.warts.Var"))
val unsafeUpdate: (ResultSet, Int, elems.type) => Unit = { (ps, n, elems) =>
var index = n
elems.iterator.foreach { e =>
Expand All @@ -85,15 +83,12 @@ object fragment {
def ++(fb: Fragment): Fragment =
new Fragment(sql + fb.sql, elems ++ fb.elems, pos orElse fb.pos)

@SuppressWarnings(Array("org.wartremover.warts.Overloading"))
def stripMargin(marginChar: Char): Fragment =
new Fragment(sql.stripMargin(marginChar), elems, pos)

@SuppressWarnings(Array("org.wartremover.warts.Overloading"))
def stripMargin: Fragment = stripMargin('|')

/** Construct a [[Query0]] from this fragment, with asserted row type `B`. */
@SuppressWarnings(Array("org.wartremover.warts.DefaultArguments"))
def query[B: Read]: Query0[B] =
queryWithLabel(unlabeled)

Expand All @@ -103,7 +98,6 @@ object fragment {
Query[elems.type, B](sql, pos, label).toQuery0(elems)

/** Construct an [[Update0]] from this fragment. */
@SuppressWarnings(Array("org.wartremover.warts.DefaultArguments"))
def update: Update0 =
updateWithLabel(unlabeled)

Expand All @@ -122,7 +116,6 @@ object fragment {
}

/** Used only for testing; this uses universal equality on the captured arguments. */
@SuppressWarnings(Array("org.wartremover.warts.Equals"))
private[util] def unsafeEquals(fb: Fragment): Boolean =
sql == fb.sql && args == fb.args

Expand Down Expand Up @@ -169,21 +162,18 @@ object fragment {
* accommodate the given list of interpolated elements. This is normally accomplished via the string interpolator
* rather than direct construction.
*/
@SuppressWarnings(Array("org.wartremover.warts.DefaultArguments"))
def apply(sql: String, elems: List[Elem], pos: Option[Pos] = None): Fragment =
new Fragment(sql, Chain.fromSeq(elems), pos)

/** Construct a statement fragment with no interpolated values and no trailing space; the passed SQL string must not
* contain `?` placeholders.
*/
@SuppressWarnings(Array("org.wartremover.warts.DefaultArguments"))
def const0(sql: String, pos: Option[Pos] = None): Fragment =
new Fragment(sql, Chain.empty, pos)

/** Construct a statement fragment with no interpolated values and a trailing space; the passed SQL string must not
* contain `?` placeholders.
*/
@SuppressWarnings(Array("org.wartremover.warts.DefaultArguments"))
def const(sql: String, pos: Option[Pos] = None): Fragment =
const0(sql + " ", pos)

Expand Down
4 changes: 0 additions & 4 deletions modules/core/src/main/scala/doobie/util/get.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ sealed abstract class Get[A](
val get: Coyoneda[(ResultSet, Int) => *, A]
) {

@SuppressWarnings(Array("org.wartremover.warts.Throw"))
final def unsafeGetNonNullable(rs: ResultSet, n: Int): A = {
val i = get.fi(rs, n)
if (rs.wasNull)
Expand Down Expand Up @@ -69,7 +68,6 @@ sealed abstract class Get[A](

/** Equivalent to `tmap`, but allows the conversion to fail with an error message.
*/
@SuppressWarnings(Array("org.wartremover.warts.Throw"))
final def temap[B](f: A => Either[String, B])(implicit sA: Show[A], evA: TypeName[A], evB: TypeName[B]): Get[B] =
tmap { a =>
f(a) match {
Expand Down Expand Up @@ -155,7 +153,6 @@ object Get extends GetInstances {
)(implicit ev: TypeName[A]): Get[A] =
Advanced(NonEmptyList.of(Some(ev.value)), NonEmptyList.of(jdbcSource), vendorTypeNames, Coyoneda.lift(get))

@SuppressWarnings(Array("org.wartremover.warts.Equals", "org.wartremover.warts.AsInstanceOf"))
def array[A >: Null <: AnyRef](vendorTypeNames: NonEmptyList[String]): Get[Array[A]] =
one(
JdbcType.Array,
Expand All @@ -166,7 +163,6 @@ object Get extends GetInstances {
}
)

@SuppressWarnings(Array("org.wartremover.warts.AsInstanceOf", "org.wartremover.warts.Throw"))
def other[A >: Null <: AnyRef: TypeName](vendorTypeNames: NonEmptyList[String])(
implicit A: ClassTag[A]
): Get[A] =
Expand Down
3 changes: 0 additions & 3 deletions modules/core/src/main/scala/doobie/util/put.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ sealed abstract class Put[A](
update = update.contramap(f)
) {}

@SuppressWarnings(Array("org.wartremover.warts.Equals"))
def unsafeSetNonNullable(ps: PreparedStatement, n: Int, a: A): Unit =
if (a == null) sys.error("oops, null")
else put.fi.apply(ps, n, (put.k(a)))
Expand All @@ -66,7 +65,6 @@ sealed abstract class Put[A](
case None => unsafeSetNull(ps, n)
}

@SuppressWarnings(Array("org.wartremover.warts.Equals"))
def unsafeUpdateNonNullable(rs: ResultSet, n: Int, a: A): Unit =
if (a == null) sys.error("oops, null")
else update.fi.apply(rs, n, (update.k(a)))
Expand Down Expand Up @@ -172,7 +170,6 @@ object Put extends PutInstances {
): Put[A] =
many(NonEmptyList.of(jdbcTarget), vendorTypeNames, put, update)

@SuppressWarnings(Array("org.wartremover.warts.Equals", "org.wartremover.warts.AsInstanceOf"))
def array[A >: Null <: AnyRef](
vendorTypeNames: NonEmptyList[String],
elementType: String
Expand Down
3 changes: 0 additions & 3 deletions modules/core/src/main/scala/doobie/util/query.scala
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ object query {
/** Apply an argument, yielding a residual `[[Query0]]`.
* @group Transformations
*/
@SuppressWarnings(Array("org.wartremover.warts.Recursion"))
def toQuery0(a: A): Query0[B] =
new Query0[B] {
def sql = outer.sql
Expand Down Expand Up @@ -214,7 +213,6 @@ object query {
* interpolator.
* @group Constructors
*/
@SuppressWarnings(Array("org.wartremover.warts.DefaultArguments"))
def apply[A, B](sql: String, pos: Option[Pos] = None, label: String = unlabeled)(implicit
A: Write[A],
B: Read[B]
Expand Down Expand Up @@ -352,7 +350,6 @@ object query {
* Note that the most common way to construct a `Query` is via the `sql`interpolator.
* @group Constructors
*/
@SuppressWarnings(Array("org.wartremover.warts.DefaultArguments"))
def apply[A: Read](sql: String, pos: Option[Pos] = None, label: String = unlabeled): Query0[A] =
Query[Unit, A](sql, pos, label).toQuery0(())

Expand Down
3 changes: 0 additions & 3 deletions modules/core/src/main/scala/doobie/util/transactor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ object transactor {
Kleisli(f.run(_).foldMap(interpret).run(c))
}

@SuppressWarnings(Array("org.wartremover.warts.DefaultArguments"))
def copy(
kernel0: A = self.kernel,
connect0: A => Resource[M, Connection] = self.connect,
Expand Down Expand Up @@ -367,10 +366,8 @@ object transactor {
*/
def fromDriverManager[M[_]] = new FromDriverManagerUnapplied[M]

@SuppressWarnings(Array("org.wartremover.warts.Overloading"))
class FromDriverManagerUnapplied[M[_]] {

@SuppressWarnings(Array("org.wartremover.warts.NonUnitStatements"))
private def create(
driver: String,
conn: () => Connection,
Expand Down
1 change: 0 additions & 1 deletion modules/core/src/main/scala/doobie/util/update.scala
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ object update {
* and/or `LogHandler` for diagnostics. The normal mechanism for construction is the `sql/fr/fr0` interpolators.
* @group Constructors
*/
@SuppressWarnings(Array("org.wartremover.warts.DefaultArguments"))
def apply[A](sql: String, pos: Option[Pos] = None, label: String = unlabeled)(
implicit W: Write[A]
): Update[A] = {
Expand Down
8 changes: 6 additions & 2 deletions modules/core/src/main/scala/doobie/util/write.scala
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,14 @@ object Write {
}

implicit val unitComposite: Write[Unit] =
Write[Unit](Nil, empty _, doNothing _, doNothing _)
Write[Unit](Nil, empty[Unit](_), doNothing[PreparedStatement, Unit](_, _, _), doNothing[ResultSet, Unit](_, _, _))

implicit val optionUnit: Write[Option[Unit]] =
Write[Option[Unit]](Nil, empty _, doNothing _, doNothing _)
Write[Option[Unit]](
Nil,
empty[Option[Unit]](_),
doNothing[PreparedStatement, Option[Unit]](_, _, _),
doNothing[ResultSet, Option[Unit]](_, _, _))

implicit def fromPut[A](implicit P: Put[A]): Write[A] =
new Write[A](
Expand Down
3 changes: 0 additions & 3 deletions modules/core/src/main/scala/doobie/util/yolo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ object yolo {

implicit class Query0YoloOps[A: TypeName](q: Query0[A]) {

@SuppressWarnings(Array("org.wartremover.warts.ToString"))
def quick(implicit colors: Colors = Colors.Ansi): M[Unit] =
q.stream
.map(_.toString)
Expand Down Expand Up @@ -90,13 +89,11 @@ object yolo {
}

implicit class ConnectionIOYoloOps[A](ca: ConnectionIO[A]) {
@SuppressWarnings(Array("org.wartremover.warts.ToString"))
def quick(implicit colors: Colors = Colors.Ansi): M[Unit] =
ca.flatMap(a => out(a.toString, colors)).transact(xa)(using ev)
}

implicit class StreamYoloOps[A](pa: Stream[ConnectionIO, A]) {
@SuppressWarnings(Array("org.wartremover.warts.ToString"))
def quick(implicit colors: Colors = Colors.Ansi): M[Unit] =
pa.evalMap(a => out(a.toString, colors)).compile.drain.transact(xa)(using ev)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class StrategySuite extends munit.FunSuite {
)

// an instrumented interpreter
@SuppressWarnings(Array("org.wartremover.warts.Var"))
class Interp extends KleisliInterpreter[IO](LogHandler.noop) {

object Connection {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class TransactorSuite extends munit.FunSuite {
assertEquals(q.transact(xa[IO]).unsafeRunSync(), 42)
}

@SuppressWarnings(Array("org.wartremover.warts.Var"))
class ConnectionTracker {
var connections = List.empty[java.sql.Connection]

Expand Down
1 change: 0 additions & 1 deletion modules/example/src/main/scala/example/FreeUsage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ object FreeUsage extends IOApp.Simple {
}(FPS.embed(_, FRS.close))
} yield l

@SuppressWarnings(Array("org.wartremover.warts.Recursion"))
def unroll[A](a: ResultSetIO[A]): ResultSetIO[List[A]] = {
def unroll0(as: List[A]): ResultSetIO[List[A]] =
FRS.next >>= {
Expand Down
5 changes: 0 additions & 5 deletions modules/example/src/main/scala/example/GenericStream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ object GenericStream extends IOApp {
type Row = Map[String, Any]

// This escapes to raw JDBC for efficiency.
@SuppressWarnings(Array(
"org.wartremover.warts.Var",
"org.wartremover.warts.While",
"org.wartremover.warts.NonUnitStatements"
))
def getNextChunkGeneric(chunkSize: Int): ResultSetIO[Seq[Row]] =
FRS.raw { rs =>
val md = rs.getMetaData
Expand Down
2 changes: 0 additions & 2 deletions modules/example/src/main/scala/example/OtherSchema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ object OtherSchema extends IOApp.Simple {
}
)

@SuppressWarnings(Array("org.wartremover.warts.Enumeration"))
object ReturnStatus extends Enumeration {
val INITIAL, IN_PROGRESS, FINISHED = Value
}

@SuppressWarnings(Array("org.wartremover.warts.ToString"))
implicit val meta: Meta[ReturnStatus.Value] =
wackyPostgresMapping(""""returns_data"."return_status"""").timap(ReturnStatus.withName)(_.toString)

Expand Down
1 change: 0 additions & 1 deletion modules/example/src/main/scala/example/StreamingCopy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ object StreamingCopy extends IOApp.Simple {
""".query[City].stream

// A consumer of cities, to be run on database 2
@SuppressWarnings(Array("org.wartremover.warts.ToString"))
def write(c: City): ConnectionIO[Unit] =
printBefore("write", c.toString)(
sql"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ object Instances {
def h2DecoderGetT[A: Decoder]: Get[A] =
Get[Json].temap(json => json.as[A].leftMap(_.show))

@SuppressWarnings(Array("org.wartremover.warts.Throw"))
def h2DecoderGet[A: Decoder]: Get[A] =
Get[Json].map(json => json.as[A].fold(throw _, identity))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class H2JsonSuite extends munit.FunSuite {
a0 <- Update[A](s"INSERT INTO TEST VALUES (?)", None).withUniqueGeneratedKeys[A]("value")(a)
} yield a0

@SuppressWarnings(Array("org.wartremover.warts.StringPlusAny"))
def testInOut[A](col: String, a: A, t: Transactor[IO])(implicit m: Get[A], p: Put[A]) = {
test(s"Mapping for $col as ${m.typeStack} - write+read $col as ${m.typeStack}") {
assertEquals(inOut(col, a).transact(t).attempt.unsafeRunSync(), Right(a))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PGConcurrentSuite extends munit.FunSuite {

import cats.effect.unsafe.implicits.global

private var dataSource: HikariDataSource = _
private var dataSource: HikariDataSource = null

private def createDataSource() = {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ object Instances {
def pgDecoderGetT[A: Decoder]: Get[A] =
Get[Json].temap(json => json.as[A].leftMap(_.show))

@SuppressWarnings(Array("org.wartremover.warts.Throw"))
def pgDecoderGet[A: Decoder]: Get[A] =
Get[Json].map(json => json.as[A].fold(throw _, identity))
}
Expand Down Expand Up @@ -74,7 +73,6 @@ object Instances {
def pgDecoderGetT[A: Decoder]: Get[A] =
Get[Json].temap(json => json.as[A].leftMap(_.show))

@SuppressWarnings(Array("org.wartremover.warts.Throw"))
def pgDecoderGet[A: Decoder]: Get[A] =
Get[Json].map(json => json.as[A].fold(throw _, identity))

Expand Down
Loading