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