HairyFotr / linter

Static Analysis Compiler Plugin for Scala
Apache License 2.0
268 stars 34 forks source link

UseOptionForeachNotPatMatch false positive? #57

Open benblack86 opened 7 years ago

benblack86 commented 7 years ago

Can't write this code using foreach since it is using tailrec. Can't think of another way to write this without using null.

  @tailrec
  final def tick(name: String, time: FiniteDuration): Unit =
    Option(times.putIfAbsent(name, time)) match { // linter:ignore UseOptionForeachNotPatMatch
      case None =>
      case Some(oldValue) =>
        if (!times.replace(name, oldValue, oldValue + time)) {
          tick(name, time)
        }
    }