Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/scala.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ jobs:
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
run: sbt "test;scalafmtCheckAll"
run: sbt "test;lintCheck"
15 changes: 15 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
rules = [
DisableSyntax
RemoveUnused
RedundantSyntax
]
DisableSyntax.noFinalize = true
DisableSyntax.noVars = true
# DisableSyntax.noNulls = true
# DisableSyntax.noFinalVal = true

RemoveUnused.imports = true
RemoveUnused.privates = false
RemoveUnused.locals = true
RemoveUnused.patternvars = false
RemoveUnused.params = false
17 changes: 16 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,18 @@ ThisBuild / version := artefactVersion
ThisBuild / organization := "net.reactivecore"
ThisBuild / scalaVersion := "3.7.4"
ThisBuild / Test / fork := true
ThisBuild / scalacOptions ++= Seq("-new-syntax", "-rewrite")
ThisBuild / scalacOptions ++= Seq(
"-new-syntax",
"-rewrite",
"-Wunused:all",
"-Wunused:strict-no-implicit-warn",
"-Wconf:any:e", // All Warnings are errors
"-Wconf:src=src_managed/.*:silent", // No Warnings inside generated code
"-Wconf:msg=unused private member&src=test/*:silent" // Do not care about unused stuff in Testcases
)

ThisBuild / semanticdbEnabled := true
ThisBuild / semanticdbVersion := scalafixSemanticdb.revision

val scalaTestVersion = "3.2.19"

Expand All @@ -54,3 +65,7 @@ lazy val root = (project in file("."))
),
publishSettings
)

addCommandAlias("lint", "scalafmtAll;scalafixAll")

addCommandAlias("lintCheck", "scalafmtCheckAll; scalafixAll --check")
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.12.2")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.3.1")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.6")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.14.5")
4 changes: 2 additions & 2 deletions src/main/scala/usql/DataType.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package usql

import java.sql.{Connection, JDBCType, PreparedStatement, ResultSet}
import java.sql.{JDBCType, PreparedStatement, ResultSet}

/** Type class describing a type to use. */
trait DataType[T] {
Expand Down Expand Up @@ -139,7 +139,7 @@ object DataType {

override def serialize(value: Option[T]): String = {
value match {
case None => s"<none>"
case None => "<none>"
case Some(value) => underlying.serialize(value)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/usql/Query.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package usql

import java.sql.{Connection, ResultSet}
import java.sql.ResultSet
import scala.util.Using

/** An SQL Query */
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/usql/dao/ColumnPathImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private[usql] case class ColumnPathSelectColumn[R, P, T](
subGetter: P => T
) extends ColumnPath[R, T] {
override def selectDynamic(name: String): ColumnPath[R, ?] = {
throw new IllegalStateException(s"Can walk further column")
throw new IllegalStateException("Can walk further column")
}

override def buildGetter: R => T = {
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/usql/dao/Macros.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package usql.dao

import usql.{DataType, RowDecoder, RowEncoder, SqlColumnId, SqlTableId}
import usql.{DataType, SqlColumnId, SqlTableId}

import scala.annotation.Annotation
import scala.compiletime.{erasedValue, summonInline}
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/usql/dao/NameMapping.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ object NameMapping {
/** Converts a string to snake case. */
def snakeCase(s: String): String = {
val builder = StringBuilder()
var lastIsUpper = false
var first = true
var lastIsUpper = false // scalafix:ok
var first = true // scalafix:ok
s.foreach { c =>
if c.isUpper && !lastIsUpper && !first then {
builder += '_'
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/usql/dao/QueryBuilder.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package usql.dao

import usql.{ConnectionProvider, Query, RowDecoder, Sql, SqlInterpolationParameter, sql}
import usql.{ConnectionProvider, Query, RowDecoder, Sql}

import java.util.UUID

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/usql/dao/QueryBuilderImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private[usql] case class SimpleTableProject[T, P](in: SimpleTableSelect[T], proj
}

override def toPreSql: Sql = {
val maybeFilterSql: SqlInterpolationParameter = in.appliedFilters match {
in.appliedFilters match {
case Some(f) => sql"WHERE ${f.toInterpolationParameter}"
case None => SqlInterpolationParameter.Empty
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/usql/dao/Rep.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package usql.dao
import usql.dao.Rep.SqlRep
import usql.{DataType, Sql, SqlInterpolationParameter, sql}

import scala.annotation.unused
import scala.language.implicitConversions

/** Typed representation for a typed value (either a [[ColumnPath]] or some raw SQL) */
Expand Down Expand Up @@ -41,11 +42,11 @@ trait Rep[T] {
SqlRep(sql"${toInterpolationParameter} OR ${rep.toInterpolationParameter}")
}

def isNull(using T => Option[?]): Rep[Boolean] = {
def isNull(using @unused optCheck: T => Option[?]): Rep[Boolean] = {
SqlRep(sql"${toInterpolationParameter} IS NULL")
}

def isNotNull(using T => Option[?]): Rep[Boolean] = {
def isNotNull(using @unused optCheck: T => Option[?]): Rep[Boolean] = {
SqlRep(sql"${toInterpolationParameter} IS NOT NULL")
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/usql/dao/SqlColumn.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package usql.dao

import usql.{DataType, Optionalize, RowDecoder, RowEncoder, SqlColumnId, SqlRawPart}
import usql.{DataType, Optionalize, RowDecoder, RowEncoder, SqlColumnId}

/** A Single Column */
case class SqlColumn[T](
Expand Down
2 changes: 0 additions & 2 deletions src/main/scala/usql/dao/SqlColumnar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package usql.dao

import usql.{Optionalize, RowDecoder, RowEncoder}

import scala.deriving.Mirror

/**
* Encapsulates column data and codecs for a product type.
*
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/usql/dao/SqlFielded.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package usql.dao

import usql.SqlInterpolationParameter.SqlParameter
import usql.{Optionalize, RowDecoder, RowEncoder, SqlColumnId, SqlInterpolationParameter}
import usql.{Optionalize, RowDecoder, RowEncoder, SqlColumnId}

import java.sql.{PreparedStatement, ResultSet}
import java.util.UUID
Expand Down Expand Up @@ -31,7 +31,7 @@ trait SqlFielded[T] extends SqlColumnar[T] {
override def rowDecoder: RowDecoder[T] = new RowDecoder {
override def parseRow(offset: Int, row: ResultSet): T = {
val fieldValues = Seq.newBuilder[Any]
var currentOffset = offset
var currentOffset = offset // scalafix:ok
fields.foreach { field =>
fieldValues += field.decoder.parseRow(currentOffset, row)
currentOffset += field.decoder.cardinality
Expand All @@ -44,7 +44,7 @@ trait SqlFielded[T] extends SqlColumnar[T] {

override def rowEncoder: RowEncoder[T] = new RowEncoder[T] {
override def encode(offset: Int, ps: PreparedStatement, value: T): Unit = {
var currentOffset = offset
var currentOffset = offset // scalafix:ok
val fieldValues = split(value)
fieldValues.zip(fields).foreach { case (fieldValue, field) =>
field.encoder.fillUnchecked(currentOffset, ps, fieldValue)
Expand Down Expand Up @@ -250,7 +250,7 @@ object SqlFielded {

case class WithColumnsRenamed[T](base: SqlFielded[T], columnIds: Seq[SqlColumnId]) extends SqlFielded[T] {
override lazy val fields: Seq[Field[?]] = {
var remainingColumns = columnIds
var remainingColumns = columnIds // scalafix:ok
val result = Seq.newBuilder[Field[?]]
base.fields.foreach {
case g: Field.Group[?] =>
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/usql/dao/SqlTabular.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package usql.dao

import usql.{RowDecoder, RowEncoder, SqlColumnId, SqlTableId}
import usql.SqlTableId

import scala.deriving.Mirror

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/usql/dao/TupleColumnPath.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package usql.dao

import usql.{SqlColumnId, SqlInterpolationParameter}
import usql.SqlColumnId

sealed trait TupleColumnPath[R, T <: Tuple] extends ColumnPath[R, T] {
final override def structure: SqlFielded[T] = structureAt(1)
Expand Down
1 change: 0 additions & 1 deletion src/main/scala/usql/profiles/BasicProfile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import usql.DataType

import java.sql.{JDBCType, PreparedStatement, ResultSet, Timestamp}
import java.time.Instant
import java.util
import scala.language.implicitConversions
import scala.reflect.ClassTag

Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/usql/AutoGeneratedUpdateTest.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package usql

import usql.dao.{ColumnPath, KeyedCrudBase, SqlColumnar, SqlTabular}
import usql.dao.{ColumnPath, KeyedCrudBase, SqlTabular}
import usql.util.TestBaseWithH2

class AutoGeneratedUpdateTest extends TestBaseWithH2 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/usql/SqlInterpolationTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class SqlInterpolationTest extends TestBase {

it should "also work in another case" in {
val inner = sql"C = ${2}"
val foo = sql"HELLO a = ${1} AND"
sql"HELLO a = ${1} AND"
val combined = (sql"HELLO a = ${1} AND ${inner}")
combined shouldBe Sql(
Seq(
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/usql/dao/ColumnPathTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class ColumnPathTest extends TestBase {
"sub2_biz"
)
path.structure shouldBe Sample.derived$SqlFielded
val subStructure = path.sub.structure.asInstanceOf[SqlFielded[SubElement]]
path.sub.structure.asInstanceOf[SqlFielded[SubElement]]

val pair: ColumnPath[Sample, (Int, Int)] = (path.x, path.y)
pair.structure.columns.map(_.id.name) shouldBe Seq(
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/usql/profiles/ProfileTestBase.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package usql.profiles

import usql.util.{TestBase, TestBaseWithDatabase, TestDatabase}
import usql.util.TestBaseWithDatabase
import usql.*
import BasicProfile.*

Expand Down
4 changes: 2 additions & 2 deletions src/test/scala/usql/util/PostgresSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ trait PostgresSupport extends TestDatabaseSupport with BeforeAndAfterEach {
private val postgresUser: String = sys.env.getOrElse("POSTGRES_USER", "postgres")
private val postgresPassword: Option[String] = sys.env.get("POSTGRES_PASSWORD")

private var _dbName: Option[String] = None
private var _dbName: Option[String] = None // scalafix:ok

protected def dbName: String = {
_dbName.getOrElse {
throw new IllegalStateException(s"DB name not initialized?!")
throw new IllegalStateException("DB name not initialized?!")
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/test/scala/usql/util/TestDatabase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import usql.ConnectionProvider

import java.sql.{Connection, DriverManager}
import java.util.Properties
import scala.util.{Random, Using}
import scala.util.Using

trait TestDatabaseSupport {

Expand All @@ -18,15 +18,15 @@ trait TestDatabase extends BeforeAndAfterEach with TestDatabaseSupport {

protected def baseSql: String = ""

private var _rootConnection: Option[Connection] = None
private var _urlAndProperties: Option[(String, Properties)] = None
private var _rootConnection: Option[Connection] = None // scalafix:ok
private var _urlAndProperties: Option[(String, Properties)] = None // scalafix:ok

protected def jdbcUrl: String = _urlAndProperties.getOrElse {
throw new IllegalStateException(s"No jdbc url")
throw new IllegalStateException("No jdbc url")
}._1

protected def jdbcPropertes: Properties = _urlAndProperties.getOrElse {
throw new IllegalStateException(s"No properties")
throw new IllegalStateException("No properties")
}._2

given cp: ConnectionProvider with {
Expand Down Expand Up @@ -61,7 +61,7 @@ trait TestDatabase extends BeforeAndAfterEach with TestDatabaseSupport {
}

protected def runSqlMultiline(sql: String): Unit = {
val splitted = splitSql(baseSql)
val splitted = splitSql(sql)
splitted.foreach { line =>
runSql(line)
}
Expand Down