Remove unnecessary else

Lift the else content of an if-else with a return statement to the outer indentation level.

P42 for VS Code
P42 for GitHub
Remove unnecessary else

Why is this refactoring helpful?

If-else chains can lead to high indentation and require keeping track of many conditions, especially when there are several levels of nesting. Introducing guard clauses or returning early can reduce the nesting level and lower the cognitive load because you can entirely rule out already covered conditions.

Related Code Actions

Learn More

Available In