KT.OPTIONAL_WHEN_BRACES

Unnecessary braces in 'when' expressions

This rule reports unnecessary braces in when expressions. These optional braces should be removed.

Noncompliant Code

Copy
val i = 1
when (i) {
    1 -> { println("one") } // unnecessary curly braces since there is only one statement
    else -> println("else")
}

Compliant Code

Copy
val i = 1
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