Unnecessary ELSE

objectscriptQuality release 
1.0.0
Id 
OS0055
Rule type 
Code Smell
Severity 

Minor

Minor
SQALE characteristic 
  • Maintainability
    • Understandability
Tags 
coding-guidelines
Remediation function 
Constant/issue
Remediation cost 
10min

Consider this code example:

    if (condition) {
        return value1
    } else {
        do something
        do somethingElse
        etc
        etc
    }

Since the if block exits unconditionally, the else may be pruned and the code then becomes:

    if (condition1) {
        return value1
    }

    do something
    do somethingElse
    etc
    etc

This rule will only trigger if the number of statements in the else block is greater than or equal to a certain threshold, which is configurable (it is 5 by default).

Parameters

NameDescriptionDefault value
nrElseStatementsThreshold
Number of statements in ELSE to trigger this rule (inclusive)
5