Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-134

Control flow statements "if", "for", "while", "switch" and "try" should not be nested too deeply

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Hide
      Refactor this code to not nest more than {} ["if", "for", "while", "switch" and "try"|"IF", "CASE", "DO", "LOOP", "SELECT", "WHILE" and "PROVIDE"|control flow] statements.
      Show
      Refactor this code to not nest more than {} ["if", "for", "while", "switch" and "try"|"IF", "CASE", "DO", "LOOP", "SELECT", "WHILE" and "PROVIDE"|control flow] statements.
    • List of parameters:
      Hide

      Key: max
      Description: Maximum allowed control flow statement nesting depth.
      Default Value: 3
      Default for PHP, Python,Go: 4
      Default for COBOL: 5
      Type: Integer

      Show
      Key: max Description: Maximum allowed control flow statement nesting depth. Default Value: 3 Default for PHP, Python,Go: 4 Default for COBOL: 5 Type: Integer
    • Default Severity:
      Critical
    • Impact:
      High
    • Likelihood:
      Low
    • Legacy Key:
      too-deeply-nested-if-statements, NestedIfDepth, NestedIf, COBOL.IfStatementNestedUsageCheck
    • Targeted languages:
      TypeScript, VB6
    • Covered Languages:
      ABAP, C#, C, C++, Cobol, Flex, Go, Java, JavaScript, Kotlin, Objective-C, PHP, PL/I, PL/SQL, Python, RPG, Ruby, Scala, Swift, T-SQL, VB.Net
    • Irrelevant for Languages:
      HTML, XML
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      10min
    • Analysis Level:
      Syntactic Analysis
    • Analysis Scope:
      Main Sources, Test Sources
    • Common Rule:
      Yes
    • Checkstyle:
      NestedForDepth, NestedIfDepth, NestedTryDepth
    • ESLint:
      max-depth
    • PMD:
      AvoidDeeplyNestedIfStmts

      Description

      Nested if, for, while, switch, and try statements are key ingredients for making what's known as "Spaghetti code".

      Such code is hard to read, refactor and therefore maintain.

        Attachments

          Issue Links

          1.
          PL/SQL: "IF" statements should not be nested too deeply RSPEC-2399 Language-Specification Active Unassigned
          2.
          Swift: Control flow statements "if", "for", "for in", "while", "do while" and "switch" should not be nested too deeply RSPEC-2489 Language-Specification Active Unassigned
          3.
          Python: Control flow statements "if", "for", "while", "try" and "with" should not be nested too deeply RSPEC-2679 Language-Specification Active Unassigned
          4.
          Java RSPEC-2719 Language-Specification Active Unassigned
          5.
          Flex: Control flow statements "if", "for", "while" and "switch" should not be nested too deeply RSPEC-2720 Language-Specification Active Unassigned
          6.
          JavaScript RSPEC-2721 Language-Specification Active Unassigned
          7.
          PHP RSPEC-2722 Language-Specification Active Unassigned
          8.
          ABAP: Control flow statements "IF", "CASE", "DO", "LOOP", "SELECT", "WHILE" and "PROVIDE" should not be nested too deeply RSPEC-2723 Language-Specification Active Unassigned
          9.
          RPG: Control flow statements "IF", "FOR", "DO", ... should not be nested too deeply RSPEC-2724 Language-Specification Active Unassigned
          10.
          Cobol: Control flow statements should not be nested too deeply RSPEC-2725 Language-Specification Active Unassigned
          11.
          C-Family RSPEC-2843 Language-Specification Active Unassigned
          12.
          VB.NET: Control flow statements "If", "For", "For Each", "Do", "While", "Select" and "Try" should not be nested too deeply RSPEC-3102 Language-Specification Active Unassigned
          13.
          C#: Control flow statements "if", "switch", "for", "foreach", "while", "do" and "try" should not be nested too deeply RSPEC-3534 Language-Specification Active Unassigned
          14.
          PL/I: "if" statements should not be nested too deeply RSPEC-4215 Language-Specification Active Unassigned
          15.
          T-SQL: Control flow statements "IF", "WHILE" and "TRY" should not be nested too deeply RSPEC-4497 Language-Specification Active Unassigned
          16.
          Go: Control flow statements "if", "for" and "switch" should not be nested too deeply RSPEC-4594 Language-Specification Active Unassigned
          17.
          Kotlin: Control flow statements "if", "for", "while", "when" and "try" should not be nested too deeply RSPEC-4701 Language-Specification Active Unassigned
          18.
          Ruby: Control flow statements "if", "for", "while", "until", "case" and "begin...rescue" should not be nested too deeply RSPEC-4762 Language-Specification Active Unassigned
          19.
          Scala: Control flow statements "if", "for", "while", "match" and "try" should not be nested too deeply RSPEC-4931 Language-Specification Active Unassigned
          20.
          Apex RSPEC-5001 Language-Specification Active Unassigned

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                freddy.mallet Freddy Mallet (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: