-
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, PL/I, RPG
-
Covered Languages:C#, C, C++, Flex, Go, Java, JavaScript, Kotlin, Objective-C, PHP, Ruby, Scala, Swift, TypeScript, VB.Net, VB6
-
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
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.
- is implemented by
-
SONARABAP-356 Rule: "switch" statements should not be nested
-
- Open
-
-
SONARCOBOL-1498 Rule: "switch" statements should not be nested
-
- Open
-
-
SONARPLI-178 Rule: "switch" statements should not be nested
-
- Open
-
-
SONARRPG-174 Rule: "switch" statements should not be nested
-
- Open
-
-
CPP-811 Rule: "switch" statements should not be nested
-
- Closed
-
-
SONARJAVA-2649 Rule S1821: "switch" statements should not be nested
-
- Closed
-
-
SONARPHP-774 Rule: "switch" statements should not be nested
-
- Closed
-
-
SONARSLANG-8 Rule S1821: "switch" statements should not be nested
-
- Closed
-
-
SONARSLANG-208 [Scala] Enable Rule: S1821 "match" statements should not be nested
-
- Closed
-
-
SONARSLANG-283 [Apex] Enable Rule: S1821 "switch" statements should not be nested
-
- Closed
-
-
SONARSWIFT-64 Rule: "switch" statements should not be nested
-
- Closed
-
-
SONARVBSIX-258 Rule: "switch" statements should not be nested
-
- Closed
-
- is related to
-
SONARJAVA-3744 Extend existing rules to support Switch Expression
-
- Closed
-
- relates to
-
RSPEC-134 Control flow statements "if", "for", "while", "switch" and "try" should not be nested too deeply
- Active
- links to
1.
|
Flex | RSPEC-1822 |
|
Active | Unassigned | |
2.
|
C-Family | RSPEC-2051 |
|
Active | Unassigned | |
3.
|
Java: "switch" statements and expressions should not be nested | RSPEC-4500 |
|
Active | Unassigned | |
4.
|
Go | RSPEC-4521 |
|
Active | Unassigned | |
5.
|
Kotlin: "when" statements should not be nested | RSPEC-4688 |
|
Active | Unassigned | |
6.
|
Ruby: "case" statements should not be nested | RSPEC-4751 |
|
Active | Unassigned | |
7.
|
Scala: "match" statements should not be nested | RSPEC-4914 |
|
Active | Unassigned | |
8.
|
Apex | RSPEC-4986 |
|
Active | Unassigned | |
9.
|
JavaScript | RSPEC-5479 |
|
Active | Unassigned | |
10.
|
PHP: "switch" statements should not be nested | RSPEC-5873 |
|
Active | Unassigned | |
11.
|
VB.NET: "Select Case" statements should not be nested | RSPEC-6039 |
|
Active | Unassigned | |
12.
|
VB6: "Select Case" statements should not be nested | RSPEC-6040 |
|
Active | Unassigned |