Skip to content

[java] OnlyOneReturn should have a property to allow early exits (guard clauses) #2801

@Springvar

Description

@Springvar

Methods guarded by null checks should be allowed to exit immediately if the checks are placed at the beginning of the method.

While this approach doesn't agree with the strictest interpretation of this rule, it is by many considered more readable than wrapping the entire method body in a if(x != null) {}

A property to allow return statements in the first N lines (default 0) should make this rule more agreeable to more developers, while still preventing return statements from being buried and scattered around the rest of the method body.

Metadata

Metadata

Assignees

No one assigned

    Labels

    an:enhancementAn improvement on existing features / rules

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions