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

"switch" statements should not be nested

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Refactor the code to eliminate this nested "switch".
    • Default Severity:
      Critical
    • Impact:
      High
    • Likelihood:
      Low
    • Targeted languages:
      ABAP, Cobol, PHP, PL/I, RPG, VB6
    • Covered Languages:
      C#, C, C++, Flex, Go, Java, JavaScript, Kotlin, Objective-C, Ruby, Scala, Swift, TypeScript, VB.Net
    • Irrelevant for Languages:
      HTML, PL/SQL, Python, T-SQL, XML
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      10min
    • Analysis Level:
      Syntactic Analysis
    • Analysis Scope:
      Main Sources, Test Sources
    • Common Rule:
      Yes
    • TSLint-SonarTS:
      no-nested-switch

      Description

      Nested switch structures are difficult to understand because you can easily confuse the cases of an inner switch as belonging to an outer statement. Therefore nested switch statements should be avoided.

      Specifically, you should structure your code to avoid the need for nested switch statements, but if you cannot, then consider moving the inner switch to another function.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                ann.campbell.2 Ann Campbell
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: