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 Scalafix #2886

Closed
wants to merge 21 commits into from
34 changes: 34 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
rules = [
Disable
DisableSyntax
ExplicitResultTypes
LeakingImplicitClassVal
NoAutoTupling
NoValInForComprehension
ProcedureSyntax
RemoveUnused
MissingFinal
EmptyCollectionsUnified
]

Disable {
ifSynthetic = [
"scala/Option.option2Iterable"
"scala/Predef.any2stringadd"
]
}

DisableSyntax.regex = []

RemoveUnused {
imports = true
privates = true
locals = true
patternvars = false
params = true
}

DisableSyntax.noReturns = true
DisableSyntax.noXml = true
DisableSyntax.noFinalize = true
DisableSyntax.noValPatterns = true
28 changes: 18 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import scala.collection.immutable.ListSet

Global / onChangedBuildSource := ReloadOnSourceChanges

val scala_v_12 = "2.12.18"
val scala_v_13 = "2.13.12"
val scala_v_30 = "3.3.1"

inThisBuild(
List(
organization := "io.getquill",
Expand All @@ -17,9 +21,19 @@ inThisBuild(
scmInfo := Some(
ScmInfo(url("https://github.com/zio/zio-quill"), "git:git@github.com:zio/zio-quill.git")
),
scalafmtCheck := true,
scalafmtSbtCheck := true,
scalafmtOnCompile := !insideCI.value
scalaVersion := scala_v_13,
crossScalaVersions := Seq(scala_v_12, scala_v_13, scala_v_30),
scalafmtCheck := true,
scalafmtSbtCheck := true,
scalafmtOnCompile := !insideCI.value,
semanticdbEnabled := scalaVersion.value.startsWith("2.13"),
semanticdbOptions += "-P:semanticdb:synthetics:on",
semanticdbVersion := scalafixSemanticdb.revision, // use Scalafix compatible version
scalafixScalaBinaryVersion := CrossVersion.binaryScalaVersion(scalaVersion.value),
scalafixDependencies ++= List(
"com.github.vovapolu" %% "scaluzzi" % "0.1.23",
"io.github.ghostbuster91.scalafix-unified" %% "unified" % "0.0.9"
)
)
)

Expand Down Expand Up @@ -618,10 +632,6 @@ def excludePaths(paths: Seq[String]) = {
})
}

val scala_v_12 = "2.12.18"
val scala_v_13 = "2.13.12"
val scala_v_30 = "3.3.1"

val scalaCollectionCompatVersion = "2.11.0"

lazy val loggingSettings = Seq(
Expand All @@ -632,8 +642,6 @@ lazy val loggingSettings = Seq(

lazy val basicSettings = excludeFilterSettings ++ Seq(
Test / testOptions += Tests.Argument("-oI"),
scalaVersion := scala_v_13,
crossScalaVersions := Seq(scala_v_12, scala_v_13, scala_v_30),
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.2.17" % Test,
"org.scala-lang.modules" %% "scala-collection-compat" % scalaCollectionCompatVersion,
Expand Down Expand Up @@ -666,7 +674,7 @@ lazy val basicSettings = excludeFilterSettings ++ Seq(
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) =>
Seq("-Ypatmat-exhaust-depth", "40")
Seq("-Ypatmat-exhaust-depth", "40", "-Ywarn-unused")
case Some((2, 12)) =>
Seq(
// "-Xfatal-warnings",
Expand Down
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.3")
addSbtPlugin("com.etsy" % "sbt-compile-quick-plugin" % "1.4.0")
addSbtPlugin("dev.zio" % "zio-sbt-website" % "0.3.10")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.1")
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class CassandraAlpakkaContext[+N <: NamingStrategy](
}
.map(_ => Done)

override def close() = {
override def close(): Unit = {
alpakkaSession.close(scala.concurrent.ExecutionContext.Implicits.global)
()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import io.getquill.context.ExecutionInfo
import io.getquill.context.cassandra.CqlIdiom
import io.getquill.context.monix.MonixContext
import io.getquill.util.{ContextLogger, LoadConfig}
import io.getquill.context.cassandra.util.FutureConversions._
import monix.eval.Task
import monix.execution.Scheduler
import monix.reactive.Observable
Expand Down Expand Up @@ -64,7 +63,7 @@ class CassandraMonixContext[+N <: NamingStrategy](
dc: Runner
): Task[List[T]] =
streamQuery[T](None, cql, prepare, extractor)(info, dc)
.foldLeftL(List[T]()) { case (l, r) => r +: l }
.foldLeftL(List.empty[T]) { case (l, r) => r +: l }
.map(_.reverse)

def executeQuerySingle[T](
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package io.getquill

import com.datastax.oss.driver.api.core.CqlSession
import com.datastax.oss.driver.api.core.cql.{AsyncResultSet, ResultSet, Row}
import com.datastax.oss.driver.api.core.cql.{AsyncResultSet, Row}
import com.typesafe.config.Config
import io.getquill.context.ExecutionInfo
import io.getquill.context.cassandra.util.FutureConversions._
import io.getquill.util.{ContextLogger, LoadConfig}
import monix.eval.Task
import monix.execution.Scheduler
import monix.execution.Scheduler.Implicits
import monix.reactive.Observable

import scala.compat.java8.FutureConverters._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import io.getquill.context.{Context, ExecutionInfo}
import io.getquill.context.cassandra.{CassandraRowContext, CqlIdiom}
import io.getquill.context.qzio.ZioContext
import io.getquill.util.Messages.fail
import io.getquill.util.ContextLogger
import zio.stream.ZStream
import zio.{Chunk, ChunkBuilder, ZEnvironment, ZIO}

Expand Down Expand Up @@ -45,8 +44,6 @@ class CassandraZioContext[+N <: NamingStrategy](val naming: N)
with Context[CqlIdiom, N]
with Probing {

private val logger = ContextLogger(classOf[CassandraZioContext[_]])

override type Error = Throwable
override type Environment = CassandraZioSession

Expand Down Expand Up @@ -94,7 +91,7 @@ class CassandraZioContext[+N <: NamingStrategy](val naming: N)
cql: String,
prepare: Prepare = identityPrepare,
extractor: Extractor[T] = identityExtractor
)(info: ExecutionInfo, dc: Runner) = {
)(info: ExecutionInfo, dc: Runner): ZStream[CassandraZioSession, Throwable, T] = {
val stream =
for {
csession <- ZStream.service[CassandraZioSession]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.getquill.context.{AsyncFutureCache, CassandraSession, SyncCache}
import io.getquill.util.LoadConfig
import zio.{ZIO, ZLayer}

case class CassandraZioSession(
final case class CassandraZioSession(
override val session: CqlSession,
override val preparedStatementCacheSize: Long
) extends CassandraSession
Expand All @@ -29,7 +29,11 @@ object CassandraZioSession {
def fromContextConfig(config: CassandraContextConfig): ZLayer[Any, Throwable, CassandraZioSession] =
ZLayer.succeed(config) >>> live

def fromConfig(config: Config) = fromContextConfig(CassandraContextConfig(config))
def fromConfig(config: Config): ZLayer[Any, Throwable, CassandraZioSession] = fromContextConfig(
CassandraContextConfig(config)
)
// Call the by-name constructor for the construction to fail inside of the effect if it fails
def fromPrefix(configPrefix: String) = fromContextConfig(CassandraContextConfig(LoadConfig(configPrefix)))
def fromPrefix(configPrefix: String): ZLayer[Any, Throwable, CassandraZioSession] = fromContextConfig(
CassandraContextConfig(LoadConfig(configPrefix))
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.datastax.oss.driver.api.core.cql.{BoundStatement, Row}
import io.getquill.context.cassandra.{CassandraRowContext, CqlIdiom}
import io.getquill.context.qzio.ZioContext
import io.getquill.context.{Context, ExecutionInfo}
import io.getquill.util.ContextLogger
import io.getquill.{CassandraZioContext, NamingStrategy}
import zio.stream.ZStream
import zio.{Tag, ZEnvironment, ZIO, ZLayer}
Expand All @@ -19,14 +18,12 @@ object Quill {
ZLayer.fromFunction((session: CassandraZioSession) => new Cassandra[N](naming, session))
}

case class Cassandra[+N <: NamingStrategy](val naming: N, session: CassandraZioSession)
final case class Cassandra[+N <: NamingStrategy](val naming: N, session: CassandraZioSession)
extends CassandraRowContext[N]
with ZioContext[CqlIdiom, N]
with Context[CqlIdiom, N]
with Probing {

private val logger = ContextLogger(classOf[Quill.Cassandra[_]])

override type Error = Throwable
override type Environment = Any

Expand Down Expand Up @@ -79,6 +76,6 @@ object Quill {
private def onSessionStream[T](zio: ZStream[CassandraZioSession, Throwable, T]) =
zio.provideEnvironment(ZEnvironment(session))

override def close() = session.close()
override def close(): Unit = session.close()
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package io.getquill

import com.datastax.oss.driver.api.core.{CqlSession, CqlSessionBuilder}
import com.datastax.oss.driver.api.core.CqlSession
import com.typesafe.config.Config
import io.getquill.context.ExecutionInfo
import io.getquill.context.cassandra.util.FutureConversions._
import io.getquill.monad.ScalaFutureIOMonad
import io.getquill.util.{ContextLogger, LoadConfig}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.datastax.oss.driver.api.core.{CqlSession, CqlSessionBuilder}
import com.typesafe.config.Config
import io.getquill.context.cassandra.cluster.SessionBuilder

case class CassandraContextConfig(config: Config) {
final case class CassandraContextConfig(config: Config) {
def preparedStatementCacheSize: Long =
if (config.hasPath("preparedStatementCacheSize"))
config.getLong("preparedStatementCacheSize")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.getquill

import java.util.Date
import io.getquill.context.cassandra.encoding.{CassandraMapper, CassandraType}
import io.getquill.context.cassandra.{CassandraContext, CqlIdiom}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.getquill.context

import com.datastax.oss.driver.api.core.cql.{BoundStatement, PreparedStatement}
import io.getquill.context.cassandra.PrepareStatementCache
import io.getquill.context.cassandra.util.FutureConversions._

import java.util.concurrent.CompletionStage
import scala.concurrent.{ExecutionContext, Future}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ trait CassandraSession extends UdtValueLookup {
.groupBy(_.getName.toString)

override def udtValueOf(udtName: String, keyspace: Option[String] = None): UdtValue =
udtMetadata.getOrElse(udtName.toLowerCase, Nil) match {
udtMetadata.getOrElse(udtName.toLowerCase, List.empty) match {
case udt :: Nil => udt.newValue()
case Nil =>
fail(s"Could not find UDT `$udtName` in any keyspace")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.getquill.context.cassandra

import java.util.{Date, UUID}
import java.util.UUID
import io.getquill.NamingStrategy
import io.getquill.context.Context
import io.getquill.context.cassandra.encoding.{CassandraMapper, Encodings}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.getquill.context.cassandra

import com.datastax.oss.driver.api.core.cql.{BoundStatement, Row}
import io.getquill.NamingStrategy
import io.getquill.context.{CassandraSession, Context, ContextVerbPrepareLambda, ExecutionInfo, UdtValueLookup}
import io.getquill.context.{CassandraSession, Context, ExecutionInfo, UdtValueLookup}
import io.getquill.context.cassandra.encoding.{CassandraTypes, Decoders, Encoders, UdtEncoding}
import io.getquill.util.ContextLogger
import io.getquill.util.Messages.fail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package io.getquill.context.cassandra

import io.getquill.{Action, Delete, EntityQuery, Insert, Query, Update}

@SuppressWarnings(Array("scalafix:ExplicitResultTypes"))
// noinspection TypeAnnotation
trait Ops {
this: CassandraContext[_] =>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.getquill.context.cassandra.cluster
import com.datastax.oss.driver.api.core.{CqlSession, CqlSessionBuilder}
import com.datastax.oss.driver.internal.core.config.typesafe.DefaultDriverConfigLoader
import com.typesafe.config.Config
import io.getquill.util.Messages._

import java.util.function.Supplier

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import io.getquill.context.UdtValueLookup
*
* End-users should rely on MappedEncoding since it's more general.
*/
case class CassandraMapper[I, O](f: (I, UdtValueLookup) => O)
final case class CassandraMapper[I, O](f: (I, UdtValueLookup) => O)
object CassandraMapper {
def simple[I, O](f: I => O): CassandraMapper[I, O] = CassandraMapper[I, O]((iOrig, _) => f(iOrig))
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.lang.{
}
import java.math.{BigDecimal => JBigDecimal}
import java.nio.ByteBuffer
import java.util.{Date, UUID}
import java.util.UUID
import java.time.{Instant, LocalDate}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.getquill.context.cassandra.encoding

import com.datastax.oss.driver.api.core.`type`.reflect.GenericType
import com.datastax.oss.driver.shaded.guava.common.reflect.{TypeParameter, TypeToken}
import io.getquill.context.cassandra.CassandraRowContext
import io.getquill.context.cassandra.util.ClassTagConversions.asClassOf

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package io.getquill.context.cassandra.encoding

import com.datastax.oss.driver.internal.core.`type`.{DefaultListType, PrimitiveType}
import com.datastax.oss.driver.internal.core.`type`.PrimitiveType
import io.getquill.context.cassandra.CassandraRowContext
import io.getquill.util.Messages.fail

import java.time.{Instant, LocalDate, LocalTime}
import java.util.{Date, UUID}
import java.util.UUID

trait Decoders extends CollectionDecoders {
this: CassandraRowContext[_] =>

type Decoder[T] = CassandraDecoder[T]

case class CassandraDecoder[T](decoder: BaseDecoder[T]) extends BaseDecoder[T] {
override def apply(index: Index, row: ResultRow, session: Session) =
override def apply(index: Index, row: ResultRow, session: Session): T =
decoder(index, row, session)
}

Expand All @@ -26,7 +26,7 @@ trait Decoders extends CollectionDecoders {
)

def decoder[T](f: ResultRow => Index => T): Decoder[T] =
decoder((index, row, session) => f(row)(index))
decoder((index, row, _) => f(row)(index))

implicit def optionDecoder[T](implicit d: Decoder[T]): Decoder[Option[T]] =
CassandraDecoder { (index, row, session) =>
Expand All @@ -41,7 +41,7 @@ trait Decoders extends CollectionDecoders {

implicit val stringDecoder: Decoder[String] = decoder(_.getString)
implicit val bigDecimalDecoder: Decoder[BigDecimal] =
decoder((index, row, session) => row.getBigDecimal(index))
decoder((index, row, _) => row.getBigDecimal(index))
implicit val booleanDecoder: Decoder[Boolean] = decoder(_.getBoolean)
implicit val byteDecoder: Decoder[Byte] = decoder(_.getByte)
implicit val shortDecoder: Decoder[Short] = decoder(_.getShort)
Expand All @@ -50,7 +50,7 @@ trait Decoders extends CollectionDecoders {
implicit val floatDecoder: Decoder[Float] = decoder(_.getFloat)
implicit val doubleDecoder: Decoder[Double] = decoder(_.getDouble)
implicit val byteArrayDecoder: Decoder[Array[Byte]] =
decoder { (index, row, session) =>
decoder { (index, row, _) =>
val bb = row.getByteBuffer(index)
val b = new Array[Byte](bb.remaining())
bb.get(b)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import io.getquill.context.cassandra.CassandraRowContext

import java.nio.ByteBuffer
import java.time.{Instant, LocalDate, LocalTime}
import java.util.{Date, UUID}
import java.util.UUID

trait Encoders extends CollectionEncoders {
this: CassandraRowContext[_] =>

type Encoder[T] = CassandraEncoder[T]

case class CassandraEncoder[T](encoder: BaseEncoder[T]) extends BaseEncoder[T] {
override def apply(index: Index, value: T, row: PrepareRow, session: Session) =
override def apply(index: Index, value: T, row: PrepareRow, session: Session): PrepareRow =
encoder(index, value, row, session)
}

Expand Down
Loading