Skip to content

Files

Latest commit

 

History

History
19 lines (10 loc) · 826 Bytes

no-var-before-return.md

File metadata and controls

19 lines (10 loc) · 826 Bytes

Pattern: Returning immediately declared variable

Issue: -

Description

Checks if the returned variable is declared right before the return statement.

Declaring a variable only to immediately return it is a bad practice. Some developers argue that the practice improves code readability, because it enables them to explicitly name what is being returned. However, this variable is an internal implementation detail that is not exposed to the callers of the method. The method name should be sufficient for callers to know exactly what will be returned.

Options

"allow-destructuring"

Allows destructuring a variable immediately before returning it.

Further Reading