KT.MANDATORY_BRACES_IF_STATEMENTS

Multi-line 'if' statement with no braces

This rule detects multi-line if statements which do not have braces. Adding braces would improve readability and avoid possible errors.

Noncompliant Code

Copy
val i = 1
if (i > 0)
    println(i)

Compliant Code

Copy
val x = if (condition) 5 else 4

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