diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeNotEqualsZero.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeNotEqualsZero.scala index ec14c577..fbb59cc7 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeNotEqualsZero.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeNotEqualsZero.scala @@ -25,9 +25,9 @@ class AvoidSizeNotEqualsZero override def inspect(tree: Tree): Unit = { tree match { case Apply( - Select(Select(_, Length | Size), TermName("$bang$eq") | TermName("$greater")), + Select(Select(q, Length | Size), TermName("$bang$eq") | TermName("$greater")), List(Literal(Constant(0))) - ) => + ) if isTraversable(q) => context.warn(tree.pos, self, tree.toString.take(100)) case _ => continue(tree) } diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeNotEqualsZeroTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeNotEqualsZeroTest.scala index f9d74e19..704f3792 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeNotEqualsZeroTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeNotEqualsZeroTest.scala @@ -25,5 +25,17 @@ class AvoidSizeNotEqualsZeroTest extends InspectionTest { compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 10 } + // github issue #414 + "should ignore durations" in { + val code = """object Test { + |case class Duration(start: Long, stop: Long) { + | def length: Long = stop - start + | def nonEmpty: Boolean = length > 0 + | } + } """.stripMargin + + compileCodeSnippet(code) + compiler.scapegoat.feedback.warnings.size shouldBe 0 + } } }