View Categories

Avoid Return Statements In If Blocks

Impact Area

Manageability

Severity

Medium

Affected Element

Lightning

Rule ID #

SF-0064

Impact

The else block in a if-else-construct is unnecessary if the if block contains a return. Then the content of the else block can be put outside. It creates an unnecessary block code, making readability harder.

Remediation #

Refactor the code, maybe moving the contents of the else block outside of the if/else statement.

Explanation #

For when an unnecessary catch block is detected. The else block in a if-else-construct is unnecessary if the if block contains a return. Then the content of the else block can be put outside.

Example

/ Bad: if (x) { return y; } else { return z; } // Good: if (x) { return y; } return z;

Time to fix

30 min

Powered by BetterDocs