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


Perl-Critic-Pulp documentation  | view source Contained in the Perl-Critic-Pulp distribution.

Index


NAME

Top

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

DESCRIPTION

Top

This policy is part of the Perl::Critic::Pulp|Perl::Critic::Pulp addon. 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]

SEE ALSO

Top

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

HOME PAGE

Top

http://user42.tuxfamily.org/perl-critic-pulp/index.html

COPYRIGHT

Top


Perl-Critic-Pulp documentation  | view source Contained in the Perl-Critic-Pulp distribution.