Conditional blocks nested three or more levels deep

ID

scala.maintainability.deep_nesting

Severity

low

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Complexity

Language

Scala

Description

This if is nested three levels deep, which makes the conditions hard to follow and hard to test. Flatten the logic with early returns, guard clauses, a match, or by extracting the inner branches into named methods.

Rationale

This if is nested three levels deep, which makes the conditions hard to follow and hard to test. Flatten the logic with early returns, guard clauses, a match, or by extracting the inner branches into named methods.

The following code illustrates the pattern detected by this rule:

class DeepNesting {
  def tooDeep(a: Boolean, b: Boolean, c: Boolean): Unit = {
    // FLAGGED: Conditional blocks nested three or more levels deep
    if (a) {
      println("one")
      if (b) {
        println("two")
        if (c) {
          println("three")
        }
      }
    }
  }
}

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved