Skip to content

Commit

Permalink
DiscardSlickDBIO
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Mar 26, 2024
1 parent cfcc12a commit a3c2d1b
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 9 deletions.
18 changes: 11 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,16 @@ lazy val rules = projectMatrix
scalacOptions += "-Ywarn-unused:imports",
Compile / sourceGenerators += task {
val dir = (Compile / sourceManaged).value
Seq(
"DiscardScalaFuture" -> "scala/concurrent/Future#",
"DiscardMonixTask" -> "monix/eval/Task#",
"DiscardEff" -> "org/atnos/eff/Eff#",
"DiscardCatsEffectIO" -> "cats/effect/IO#",
).map { case (ruleName, tpe) =>
Seq[(String, Seq[String])](
"DiscardSlickDBIO" -> Seq(
"slick/dbio/package.DBIO#",
"slick/dbio/DBIOAction#",
),
"DiscardScalaFuture" -> Seq("scala/concurrent/Future#"),
"DiscardMonixTask" -> Seq("monix/eval/Task#"),
"DiscardEff" -> Seq("org/atnos/eff/Eff#"),
"DiscardCatsEffectIO" -> Seq("cats/effect/IO#"),
).map { case (ruleName, types) =>
val f = dir / "fix" / s"${ruleName}.scala"
IO.write(
f,
Expand All @@ -139,7 +143,7 @@ lazy val rules = projectMatrix
| config.conf.getOrElse("${ruleName}")(this.config).map(newConfig => new ${ruleName}(newConfig))
|
| override def fix(implicit doc: SemanticDocument): Patch =
| DiscardValue.typeRef(config.toDiscardValueConfig("${tpe}"))
| DiscardValue.typeRef(config.toDiscardValueConfig(${types.map("\"" + _ + "\"")}))
|
|}
|""".stripMargin
Expand Down
65 changes: 65 additions & 0 deletions input/src/main/scala-2/fix/DiscardSlickDBIOTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
rule = DiscardSlickDBIO
*/
package fix

import slick.dbio.DBIO
import scala.concurrent.ExecutionContext
import org.mockito.Mockito
import org.mockito.Mockito.verify

trait DiscardSlickDBIOTest {
def f0[R]: DBIO[Int]

def f1[R](n: Int): DBIO[Int]

def g[A](x: Option[DBIO[A]]): Option[Int] = {
x.map(y => 3) // assert: DiscardSlickDBIO
x.map(_ => 3) // TODO
x.map(implicit y => 3)
x.map { y =>
println(y)
4
}
}

def mock: DiscardSlickDBIOTest

f0[Int] // assert: DiscardSlickDBIO

def f2[R](implicit ec: ExecutionContext): DBIO[Int] = {
f0[R] // assert: DiscardSlickDBIO

f1[R](2) // assert: DiscardSlickDBIO

f1[R](3).map(_ + 4) // assert: DiscardSlickDBIO

val x1 = f1[R](5)
def x2: DBIO[Int] = f1[R](5)

Mockito.verify(mock).f1(3)
Mockito.verify(mock).f1[R](3)
Mockito.verify(mock, Mockito.times(2)).f1(9)
Mockito.verify(mock, Mockito.times(2)).f1[R](9)
Mockito.verify(mock, Mockito.never()).f1(-1)
Mockito.verify(mock, Mockito.never()).f1[R](-1)

verify(mock).f0[R]
verify(mock).f1(4)
verify(mock).f1[R](4)
verify(mock, Mockito.times(2)).f1(5)
verify(mock, Mockito.times(2)).f1[R](5)
verify(mock, Mockito.never()).f1(8)
verify(mock, Mockito.never()).f1[R](8)

x1.flatMap(y => x1.map(_ + y)) // assert: DiscardSlickDBIO

x1 // assert: DiscardSlickDBIO

var mutableValue: DBIO[Int] = null

mutableValue = x1

x1
}
}
3 changes: 1 addition & 2 deletions rules/src/main/scala/fix/DiscardSingleConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import scalafix.lint.LintSeverity
case class DiscardSingleConfig(
severity: LintSeverity
) {
def toDiscardValueConfig(tpe: String): DiscardValueConfig = {
val types = Seq(tpe)
def toDiscardValueConfig(types: Seq[String]): DiscardValueConfig = {
severity match {
case LintSeverity.Info =>
DiscardValueConfig.default.copy(info = types)
Expand Down

0 comments on commit a3c2d1b

Please sign in to comment.