From 3a2243cb449dd2a7edc5d1993d783714d9ba0c24 Mon Sep 17 00:00:00 2001 From: xuwei-k <6b656e6a69@gmail.com> Date: Sat, 13 Jan 2024 19:19:48 +0900 Subject: [PATCH] filter org.mockito.InOrder --- .../src/main/scala-2/fix/DiscardValueTest.scala | 4 ++++ rules/src/main/scala/fix/DiscardValue.scala | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/input/src/main/scala-2/fix/DiscardValueTest.scala b/input/src/main/scala-2/fix/DiscardValueTest.scala index 63a14ac..6eca8a3 100644 --- a/input/src/main/scala-2/fix/DiscardValueTest.scala +++ b/input/src/main/scala-2/fix/DiscardValueTest.scala @@ -16,6 +16,8 @@ trait DiscardValueTest { def mock: DiscardValueTest + val inOrder: org.mockito.InOrder + f0[Int] // assert: DiscardValue def f2[R]: Option[Int] = { @@ -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) diff --git a/rules/src/main/scala/fix/DiscardValue.scala b/rules/src/main/scala/fix/DiscardValue.scala index 6377036..f83c503 100644 --- a/rules/src/main/scala/fix/DiscardValue.scala +++ b/rules/src/main/scala/fix/DiscardValue.scala @@ -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, @@ -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) =>