KT.DUPLICATE_CASE_IN_WHEN_EXPRESSION

Duplicate case statements in when expressions

Flags duplicate case statements in when expressions. If a when expression contains the same case statement multiple times they should be merged. Otherwise, it might be easy to miss one of the cases when reading the code, leading to unwanted side effects.

Noncompliant Code

Copy
when (i) {
  1 -> println("one")
  1 -> println("one")
  else -> println("else")
}

Compliant Code

Copy
when (i) {
  1 -> println("one")
  else -> println("else")
}

The content on this page is adapted from the Detekt Docs. Copyright ©2022 The Detekt Team. All rights reserved. https://detekt.dev/comments.html