-
-
28 Feb 2021 08:34:14 UTC
- Distribution: Perl-Critic-Pulp
- Module version: 99
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Issues (7)
- Testers (975 / 10 / 0)
- Kwalitee
Bus factor: 1- 81.76% Coverage
- License: gpl_3
- Perl: v5.6.0
- Activity
24 month- Tools
- Download (217.29KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
- Dependencies
- IO::String
- List::MoreUtils
- List::Util
- PPI
- PPI::Document
- PPI::Dumper
- Perl::Critic
- Perl::Critic::Policy
- Perl::Critic::Utils
- Perl::Critic::Utils::PPI
- Perl::Critic::Violation
- Pod::Escapes
- Pod::MinimumVersion
- Pod::ParseLink
- Pod::Parser
- Scalar::Util
- Test::More
- version
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Perl::Critic::Policy::ValuesAndExpressions::ProhibitNullStatements - disallow empty statements (stray semicolons)
DESCRIPTION
This policy is part of the
Perl::Critic::Pulp
add-on. It prohibits empty statements, ie. bare;
semicolons. This can be a typo doubling up a semi likeuse Foo;; # bad
Or a stray left at the end of a control structure like
if ($foo) { print "foo\n"; return; }; # bad
An empty statement is harmless, so this policy is under the "cosmetic" theme (see "POLICY THEMES" in Perl::Critic) and medium severity. It's surprisingly easy to leave a semi behind when chopping code around, especially when changing a statement to a loop or conditional.
Allowed forms
A C style
for (;;) { ...}
loop is ok. Those semicolons are expression separators and empties there are quite usual.for (;;) { # ok print "infinite loop\n"; }
A semicolon at the start of a
map
orgrep
block is allowed. It's commonly used to ensure Perl parses it as a block, not an anonymous hash. (Perl decides at the point it parses the{
. A;
there forces a block when it might otherwise guess wrongly. See "map" in perlfunc for more on this.)map {; $_, 123} @some_list; # ok grep {# this is a block ; # ok length $_ and $something } @some_list;
The
map
form is much more common than thegrep
, but both suffer the same ambiguity.grep
doesn't normally inspire people to quite such convoluted forms asmap
does.Try/Catch Blocks
The
Try
,TryCatch
andSyntax::Feature::Try
modules all add newtry
block statement forms. These statements don't require a terminating semicolon (the same as anif
doesn't require one). Any semicolon there is reckoned as a null statement.use TryCatch; sub foo { try { attempt_something() } catch { error_recovery() }; # bad }
This doesn't apply to other try modules such as
Try::Tiny
and friends. They're implemented as ordinary function calls (with prototypes), so a terminating semicolon is normal for them.use Try::Tiny; sub foo { try { attempt_something() } catch { error_recovery() }; # ok }
CONFIGURATION
allow_perl4_semihash
(boolean, default false)-
If true then Perl 4 style documentation comments like the following are allowed.
;# Usage: ;# require 'mypkg.pl'; ;# ...
The
;
must be at the start of the line. This is fairly outdated, so it's disabled by default. If you're crunching through some old code you can enable it by adding to your .perlcriticrc file[ValuesAndExpressions::ProhibitNullStatements] allow_perl4_semihash=1
SEE ALSO
Perl::Critic::Pulp, Perl::Critic, Perl::Critic::Policy::CodeLayout::RequireFinalSemicolon
HOME PAGE
http://user42.tuxfamily.org/perl-critic-pulp/index.html
COPYRIGHT
Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde
Perl-Critic-Pulp is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Perl-Critic-Pulp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Perl-Critic-Pulp. If not, see <http://www.gnu.org/licenses/>.
Module Install Instructions
To install Perl::Critic::Pulp, copy and paste the appropriate command in to your terminal.
cpanm Perl::Critic::Pulp
perl -MCPAN -e shell install Perl::Critic::Pulp
For more information on module installation, please visit the detailed CPAN module installation guide.