Skip to content

Commit

Permalink
filter org.mockito.InOrder
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Jan 13, 2024
1 parent a30745d commit 3a2243c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions input/src/main/scala-2/fix/DiscardValueTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ trait DiscardValueTest {

def mock: DiscardValueTest

val inOrder: org.mockito.InOrder

f0[Int] // assert: DiscardValue

def f2[R]: Option[Int] = {
Expand All @@ -25,6 +27,8 @@ trait DiscardValueTest {

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

inOrder.verify(5)

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

Expand Down
17 changes: 17 additions & 0 deletions rules/src/main/scala/fix/DiscardValue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ object DiscardValue {
.asPatch
}

private object MockitoInOrder {
def unapply(x: Term)(implicit doc: SemanticDocument): Boolean = {
x.symbol.info.fold(false)(x =>
PartialFunction.cond(x.signature) { case m: MethodSignature =>
PartialFunction.cond(m.returnType) { case t: TypeRef =>
t.symbol.value == "org/mockito/InOrder#"
}
}
)
}
}

def fix(
message: SemanticType => String,
severity: LintSeverity,
Expand All @@ -103,6 +115,11 @@ object DiscardValue {
()
case Term.Apply.After_4_6_0(Term.Name("verify"), _) =>
()
case Term.Apply.After_4_6_0(
Term.Select(MockitoInOrder(), Term.Name("verify")),
_
) =>
()
}.isEmpty
}.flatMap(x => x.symbol.info.map(x -> _))
.map { case (x, info) =>
Expand Down

0 comments on commit 3a2243c

Please sign in to comment.