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, JavaScript, PHP, PL/I, RPG, VB6
    • Covered Languages:
      C#, C, C++, Flex, Go, Java, 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

          1.
          Flex RSPEC-1822 Language-Specification Active Unassigned
          2.
          C-Family RSPEC-2051 Language-Specification Active Unassigned
          3.
          Java RSPEC-4500 Language-Specification Active Unassigned
          4.
          Go RSPEC-4521 Language-Specification Active Unassigned
          5.
          Kotlin: "when" statements should not be nested RSPEC-4688 Language-Specification Active Unassigned
          6.
          Ruby: "case" statements should not be nested RSPEC-4751 Language-Specification Active Unassigned
          7.
          Scala: "match" statements should not be nested RSPEC-4914 Language-Specification Active Unassigned
          8.
          Apex RSPEC-4986 Language-Specification Active Unassigned
          9.
          TypeScript RSPEC-5165 Language-Specification Active Unassigned

            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: