« Policy/CodeLayout/RequireFinalSemicolon.pm
↑ Summary
Policy/ValuesAndExpressions/ProhibitArrayAssignAref.pm »
| 1 | # Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # This file is part of Perl-Critic-Pulp. | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | # Perl-Critic-Pulp is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # it under the terms of the GNU General Public License as published by the | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # Free Software Foundation; either version 3, or (at your option) any later | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # version. | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # Perl-Critic-Pulp is distributed in the hope that it will be useful, but | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # for more details. | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # You should have received a copy of the GNU General Public License along | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # with Perl-Critic-Pulp. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | package Perl::Critic::Policy::ValuesAndExpressions::ProhibitEmptyCommas; | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 40 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 40 | ▶ | use base 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 40 | ▶ | use Perl::Critic::Utils; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 40 | ▶ | use Perl::Critic::Pulp::Utils; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | # uncomment this to run the ### lines | ||||||||||||||||||||||||||||||||||||||||||
| 28 | # use Smart::Comments; | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 40 | our $VERSION = 100; | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 40 | ▶ | use constant supported_parameters => (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 40 | ▶ | use constant default_severity => $Perl::Critic::Utils::SEVERITY_LOW; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 40 | ▶ | use constant default_themes => qw(pulp cosmetic); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 40 | ▶ | use constant applies_to => ('PPI::Token::Operator'); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 72 | ▶ | sub violates { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
violates: called CC=13 SCAR=26.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 72 | my ($self, $elem, $document) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 72 | ▶ | $Perl::Critic::Pulp::Utils::COMMA{$elem} or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 54 | my $prev = $elem->sprevious_sibling; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 54 | ▶ | if ($prev && ! ($prev->isa('PPI::Token::Operator') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$prev and not $prev->isa("PPI::Token::Operator") && $Perl::Critic::Pulp::Utils::COMMA{$prev}
$prev->isa('PPI::Token::Operator') && $Perl::Critic::Pulp::Utils::COMMA{$prev}
MC/DC100%3/3
$prev and not $prev->isa("PPI::Token::Operator") && $Perl::Critic::Pulp::Utils::COMMA{$prev}
$prev
$prev->isa('PPI::Token::Operator')
$Perl::Critic::Pulp::Utils::COMMA{$prev}
Truth table100%4/4
A and not(B && C)
A= $prevB= $prev->isa('PPI::Token::Operator')C= $Perl::Critic::Pulp::Utils::COMMA{$prev}
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | && $Perl::Critic::Pulp::Utils::COMMA{$prev})) { | ||||||||||||||||||||||||||||||||||||||||||
| 46 | # have a previous element and it's not a comma operator | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 30 | return; | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | # A statement like | ||||||||||||||||||||||||||||||||||||||||||
| 51 | # | ||||||||||||||||||||||||||||||||||||||||||
| 52 | # return bless({@_}, $class) | ||||||||||||||||||||||||||||||||||||||||||
| 53 | # | ||||||||||||||||||||||||||||||||||||||||||
| 54 | # is parsed by PPI as | ||||||||||||||||||||||||||||||||||||||||||
| 55 | # | ||||||||||||||||||||||||||||||||||||||||||
| 56 | # PPI::Structure::List ( ... ) | ||||||||||||||||||||||||||||||||||||||||||
| 57 | # PPI::Statement::Compound | ||||||||||||||||||||||||||||||||||||||||||
| 58 | # PPI::Structure::Block { ... } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | # PPI::Statement | ||||||||||||||||||||||||||||||||||||||||||
| 60 | # PPI::Token::Magic '@_' | ||||||||||||||||||||||||||||||||||||||||||
| 61 | # PPI::Statement::Expression | ||||||||||||||||||||||||||||||||||||||||||
| 62 | # PPI::Token::Operator ',' | ||||||||||||||||||||||||||||||||||||||||||
| 63 | # PPI::Token::Symbol '$class' | ||||||||||||||||||||||||||||||||||||||||||
| 64 | # | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # so the "{@_}" bit is not an immediate predecessor of the "," operator. | ||||||||||||||||||||||||||||||||||||||||||
| 66 | # If our $elem has no $prev then also look outwards to see if it's at the | ||||||||||||||||||||||||||||||||||||||||||
| 67 | # start of an expression which is in a list and there's something | ||||||||||||||||||||||||||||||||||||||||||
| 68 | # preceding in the list. | ||||||||||||||||||||||||||||||||||||||||||
| 69 | # | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 24 | ▶ | if (! $prev) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 11 | my $parent = $elem->parent; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 11 | ▶ | if ($parent->isa('PPI::Statement::Expression') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$parent->isa("PPI::Statement::Expression") and $parent->parent->isa("PPI::Structure::List") and $parent->sprevious_sibling
$parent->isa("PPI::Statement::Expression") and $parent->parent->isa("PPI::Structure::List")
MC/DC0%0/3
$parent->isa("PPI::Statement::Expression") and $parent->parent->isa("PPI::Structure::List") and $parent->sprevious_sibling
$parent->isa("PPI::Statement::Expression")
$parent->parent->isa("PPI::Structure::List")
$parent->sprevious_sibling
Truth table50%2/4
A and B and C
A= $parent->isa("PPI::Statement::Expression")B= $parent->parent->isa("PPI::Structure::List")C= $parent->sprevious_sibling
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | && $parent->parent->isa('PPI::Structure::List') | ||||||||||||||||||||||||||||||||||||||||||
| 74 | && $parent->sprevious_sibling) { | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | # An expression like | ||||||||||||||||||||||||||||||||||||||||||
| 80 | # | ||||||||||||||||||||||||||||||||||||||||||
| 81 | # [{%a},{}] | ||||||||||||||||||||||||||||||||||||||||||
| 82 | # | ||||||||||||||||||||||||||||||||||||||||||
| 83 | # is parsed by PPI 1.215 as | ||||||||||||||||||||||||||||||||||||||||||
| 84 | # | ||||||||||||||||||||||||||||||||||||||||||
| 85 | # PPI::Statement | ||||||||||||||||||||||||||||||||||||||||||
| 86 | # PPI::Structure::Constructor [ ... ] | ||||||||||||||||||||||||||||||||||||||||||
| 87 | # PPI::Statement::Compound | ||||||||||||||||||||||||||||||||||||||||||
| 88 | # PPI::Structure::Block { ... } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | # PPI::Statement | ||||||||||||||||||||||||||||||||||||||||||
| 90 | # PPI::Token::Symbol '%a' | ||||||||||||||||||||||||||||||||||||||||||
| 91 | # PPI::Statement | ||||||||||||||||||||||||||||||||||||||||||
| 92 | # PPI::Token::Operator ',' | ||||||||||||||||||||||||||||||||||||||||||
| 93 | # PPI::Structure::Constructor { ... } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | # | ||||||||||||||||||||||||||||||||||||||||||
| 95 | # so the "{%a}" bit is not an immediate predecessor of the "," operator. | ||||||||||||||||||||||||||||||||||||||||||
| 96 | # If our $elem has no $prev then also look upwards to see if it's at the | ||||||||||||||||||||||||||||||||||||||||||
| 97 | # start of an statement which is in a constructor and there's something | ||||||||||||||||||||||||||||||||||||||||||
| 98 | # preceding in that constructor. | ||||||||||||||||||||||||||||||||||||||||||
| 99 | # | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 24 | ▶ | if (! $prev) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 11 | my $parent = $elem->parent; | |||||||||||||||||||||||||||||||||||||||||
| 102 | ### parent: ref $parent | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 11 | ▶ | if ($parent->isa('PPI::Statement') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$parent->isa("PPI::Statement") and $parent->parent->isa("PPI::Structure::Constructor") and $parent->sprevious_sibling
$parent->isa("PPI::Statement") and $parent->parent->isa("PPI::Structure::Constructor")
MC/DC33%1/3
$parent->isa("PPI::Statement") and $parent->parent->isa("PPI::Structure::Constructor") and $parent->sprevious_sibling
$parent->isa("PPI::Statement")
$parent->parent->isa("PPI::Structure::Constructor")
$parent->sprevious_sibling
Truth table50%2/4
A and B and C
A= $parent->isa("PPI::Statement")B= $parent->parent->isa("PPI::Structure::Constructor")C= $parent->sprevious_sibling
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | && $parent->parent->isa('PPI::Structure::Constructor') | ||||||||||||||||||||||||||||||||||||||||||
| 105 | && $parent->sprevious_sibling) { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | # $prev is either nothing or a comma operator | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 19 | return $self->violation ('Empty comma operator', | |||||||||||||||||||||||||||||||||||||||||
| 112 | '', | ||||||||||||||||||||||||||||||||||||||||||
| 113 | $elem); | ||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 40 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 117 | __END__ | ||||||||||||||||||||||||||||||||||||||||||