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::ValuesAndExpressions::ProhibitEmptyCommas - disallow empty consecutive commas

Description

       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),

           [-ValuesAndExpressions::ProhibitEmptyCommas]

Home Page

Name

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

See Also

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

See Also