Skip to content

A perlcritic policy that checks for return followed by a lower-precedence operator

License

Notifications You must be signed in to change notification settings

ZipRecruiter/Perl-Critic-Policy-BuiltinFunctions-ProhibitReturnOr

Repository files navigation

NAME

Perl::Critic::Policy::BuiltinFunctions::ProhibitReturnOr - Check for "return $x or ..."

DESCRIPTION

return when encountered in an expression returns from the enclosing subroutine, without evaluating the rest of the expression. So a lower-precedence operator (or, and, xor) won't get evaluated after a return. This most commonly appears as the mis-idiom:

# NO! DON'T DO THIS!
return $x or die 'Aaaagh! $x was zero!';

Instead, use the higher-precedence || operator, like this:

return $x || die 'Aaaagh! $x was zero!';

Or separate the two operations, like this:

$x or die 'Aaaagh! $x was zero!';
return $x;

CONFIGURATION

This Policy is not configurable except for the standard options.

LICENSE

Copyright (C) 2016 Jeremy Leader.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

ACKNOWLEDGEMENTS

Thanks to ZipRecruiter for encouraging their employees to contribute back to the open source ecosystem. Without their dedication to quality software development this distribution would not exist.

AUTHOR

Jeremy Leader [email protected]

SEE ALSO

Perl::Critic

About

A perlcritic policy that checks for return followed by a lower-precedence operator

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages