logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Perl::Critic::Policy::Community::ConditionalImplicitReturn - Don't end a subroutine with a conditional

Affiliation

       This policy is part of Perl::Critic::Community.

Author

       Dan Book, "dbook@cpan.org"

Caveats

       This policy currently only checks for implicitly returned conditionals in named subroutines, anonymous
       subroutines are not checked. Also, return statements within blocks, other than compound statements like
       "if" and "foreach", are not considered when determining if a function is intended to be used in void
       context.

Configuration

       This policy is not configurable except for the standard options.

Description

       If the last statement in a subroutine is a conditional block such as "if ($foo) { ... }", and the "else"
       condition is not handled, the subroutine will return an unexpected value when the condition fails, and it
       is most likely a logic error. Specify a return value after the conditional, or handle the "else"
       condition.

         sub { ... if ($foo) { return 1 } }                   # not ok
         sub { ... if ($foo) { return 1 } return 0 }          # ok
         sub { ... if ($foo) { return 1 } else { return 0 } } # ok

       This policy only applies if the subroutine contains a return statement with an explicit return value,
       indicating it is not intended to be used in void context.

Name

       Perl::Critic::Policy::Community::ConditionalImplicitReturn - Don't end a subroutine with a conditional
       block

See Also

       Perl::Critic

perl v5.40.1                                       2025-03-22             Perl::Critic::P...lImplicitReturn(3pm)

See Also