Kevin Ryde > Perl-Critic-Pulp > Perl::Critic::Policy::ValuesAndExpressions::ProhibitEmptyCommas



Annotate this POD



Open  1
View/Report Bugs
Module Version: 80   Source  


Perl::Critic::Policy::ValuesAndExpressions::ProhibitEmptyCommas - disallow empty consecutive commas


This policy is part of the Perl::Critic::Pulp add-on. It prohibits empty comma operators , or => meaning either consecutive commas or a comma at the start of a list or expression.

    print 'foo',,'bar';      # bad
    @a = (,1,2);             # bad
    foo (x, => 123);         # bad
    a =>=> 456;              # bad
    for (; $i++<10; $i++,,)  # bad
    func (,)                 # bad

Extra commas like this are harmless and simply collapse out when the program runs (see "List value constructors" in perldata), so this policy is only under the "cosmetic" theme (see "POLICY THEMES" in Perl::Critic). Usually this sort of thing is just a stray, or leftover from cut and paste, or perhaps some over-enthusiastic column layout. Occasionally it can be something more dubious,

    # did you mean 1..6 range operator?
    @a = (1,,6);        # bad

    # this is two args, did you want three?
    foo (1, , 2);       # bad

    # this is three args, probably you forgot a value
    bar (abc => ,       # bad
         def => 20);

A comma at the end of a list or call is allowed. That's quite usual and can be a good thing when cutting and pasting lines (see RequireTrailingCommas to mandate them!).

    @b = ("foo",
          "bar",  # ok

If you use multiple commas in some systematic way for code layout you can always disable ProhibitEmptyCommas from your .perlcriticrc file in the usual way (see "CONFIGURATION" in Perl::Critic),



Perl::Critic::Pulp, Perl::Critic, Perl::Critic::Policy::CodeLayout::RequireTrailingCommas, Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements, Perl::Critic::Policy::Tics::ProhibitManyArrows



Copyright 2008, 2009, 2010, 2011, 2012, 2013 Kevin Ryde




syntax highlighting: