-
Type:
Code Smell Detection
-
Status: Active
-
Resolution: Unresolved
-
Labels:
-
Message:Merge this if statement with the (enclosing|nested) one.
-
Highlighting:
- Primary: nesting if (condition)
- Additional: nested if (condition)
- message: (Enclosing|Nested) "if" statement
-
Default Severity:Major
-
Impact:Low
-
Likelihood:High
-
Default Quality Profiles:Sonar way
-
Legacy Key:CollapsibleIfStatements
-
Targeted languages:APEX, PL/I, RPG, Rust, Solidity, VB6
-
Covered Languages:ABAP, C#, C, C++, Cobol, Flex, Go, Java, JavaScript, Kotlin, Objective-C, PHP, PL/SQL, Python, Ruby, Scala, Swift, T-SQL, TypeScript, VB.Net
-
Irrelevant for Languages:HTML, XML
-
Remediation Function:Constant/Issue
-
Constant Cost:5min
-
Analysis Level:Syntactic Analysis
-
Analysis Scope:Main Sources, Test Sources
-
Common Rule:Yes
-
PMD:CollapsibleIfStatements
-
TSLint-SonarTS:no-collapsible-if
Merging collapsible if statements increases the code's readability.
Noncompliant Code Example
if (file != null) { if (file.isFile() || file.isDirectory()) { /* ... */ } }
Compliant Solution
if (file != null && isFileOrDirectory(file)) { /* ... */ } private static boolean isFileOrDirectory(File file) { return file.isFile() || file.isDirectory(); }
- is implemented by
-
SONARPLI-160 Rule: Collapsible "if" statements should be merged
-
- Open
-
-
SONARRPG-161 Rule: Collapsible "if" statements should be merged
-
- Open
-
-
SONARVBSIX-236 Rule: Collapsible "if" statements should be merged
-
- Open
-
-
SONARCOBOL-1149 Rule: Collapsible "if" statements should be merged
-
- Closed
-
-
SONARPY-17 Rule: Collapsible "if" statements should be merged
-
- Closed
-
-
SONARSLANG-6 Rule S1066: Collapsible "if" statements should be merged
-
- Closed
-
-
SONARSLANG-206 [Scala] Enable Rule: S1066 Collapsible "if" statements should be merged
-
- Closed
-
-
SONARSLANG-279 [Apex] Enable Rule: S1066 Collapsible "if" statements should be merged
-
- Closed
-
-
SONARSWIFT-53 Rule: Collapsible "if" statements should be merged
-
- Closed
-
-
SONARTSQL-24 Rule: Collapsible "if" statements should be merged
-
- Closed
-
-
SONARVB-274 Rule: Collapsible "if" statements should be merged
-
- Closed
-
-
CPP-707 Create Objective-C rules repository containing targeted rules
-
- Closed
-
-
SONARABAP-156 Update title and description of rule "Avoid collapsible IF statements"
-
- Closed
-
-
SONARPLSQL-496 Rule: Collapsible "if" statements should be merged
-
- Closed
-
- is related to
-
CPP-367 Rule: Collapsible 'if' statements should be merged
-
- Closed
-
- links to
1.
|
PHP | RSPEC-2379 |
|
Active | Unassigned | |
2.
|
ABAP | RSPEC-2380 |
|
Active | Unassigned | |
3.
|
PL/SQL | RSPEC-2381 |
|
Active | Unassigned | |
4.
|
VB6 | RSPEC-2382 |
|
Active | Unassigned | |
5.
|
JavaScript | RSPEC-2383 |
|
Active | Unassigned | |
6.
|
Swift | RSPEC-2500 |
|
Active | Unassigned | |
7.
|
C-Family | RSPEC-2889 |
|
Active | Unassigned | |
8.
|
C# | RSPEC-2913 |
|
Active | Unassigned | |
9.
|
Flex | RSPEC-3295 |
|
Active | Unassigned | |
10.
|
Cobol: Collapsible "IF" statements should be merged | RSPEC-3720 |
|
Active | Unassigned | |
11.
|
Python | RSPEC-4006 |
|
Active | Unassigned | |
12.
|
T-SQL | RSPEC-4096 |
|
Active | Unassigned | |
13.
|
Go | RSPEC-4596 |
|
Active | Unassigned | |
14.
|
Kotlin | RSPEC-4683 |
|
Active | Unassigned | |
15.
|
Ruby | RSPEC-4755 |
|
Active | Unassigned | |
16.
|
Scala | RSPEC-4909 |
|
Active | Unassigned | |
17.
|
Apex | RSPEC-4965 |
|
Active | Unassigned | |
18.
|
VB.NET | RSPEC-5220 |
|
Active | Unassigned |