Skip to content

Latest commit

 

History

History
64 lines (46 loc) · 1.89 KB

NestedStatements.md

File metadata and controls

64 lines (46 loc) · 1.89 KB

Control flow statements should not be nested too deep (NestedStatements)

Type Scope Severity Activated
by default
Minutes
to fix
Tags
Code smell BSL
OS
Critical Yes 30 badpractice
brainoverload

Parameters

Name Type Description Default value
maxAllowedLevel Integer Max nested level 4

Description

Nested "If, "For", "For Each", "While" and "Try" operators are the key ingredients for creating so-called "spaghetti code".

Such code is hard for reading, refactoring and support.

Examples

Wrong

If Something Then                  // Allowed - level = 1
  /* ... */
  If Some Then             // Allowed - level = 2
    /* ... */
    For Num = 0 To 10 Do          // Allowed - level = 3
      /* ... */
      If OneMoreCondition Then     // Acceptable - level = 4, limit is reached, not yet breached
        If SomethingElse Then        // Level = 5, Limit is breached
          /* ... */
        EndIf;
        Return;
      EndIf;
    EndDo;
  EndIf;
EndIf;

Sources

Snippets

Diagnostic ignorance in code

// BSLLS:NestedStatements-off
// BSLLS:NestedStatements-on

Parameter for config

"NestedStatements": {
    "maxAllowedLevel": 4
}