The indentation of else
branch should be unambiguous
- AMBIGUOUS_ELSE_BRANCH
- Code Quality
- Low
- cwe
This rule applies when else
branches are indented ambiguously.
Without braces ({}
), the else
branch belongs to the nearest if
statement. This rule detects an alarm when the else
branch is ambiguously aligned with an outer if
statement.
Noncompliant Code Example
View with compliant examples side by sideif (a)
if (b)
foo();
else // AMBIGUOUS_ELSE_BRANCH alarm
bar();
Compliant Code Example
View with noncompliant examples side by sideif (a) {
if (b) {
foo();
} else {
bar();
}
}
// or
if (a) {
if (b) {
foo();
}
} else {
bar();
}
Version
This rule was introduced in DeepScan 1.28.0.