« lib/Perl/Critic/Policy/RegularExpressions/ProhibitEnumeratedClasses.pm
↑ Summary
lib/Perl/Critic/Policy/ControlStructures/ProhibitUnreachableCode.pm »
| 1 | package Perl::Critic::Policy::CodeLayout::RequireTrailingCommas; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 40 | ▶ | use 5.010001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 40 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 40 | ▶ | use Perl::Critic::Utils qw{ :characters :severities }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 40 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 40 | our $VERSION = '1.156'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 40 | Readonly::Scalar my $DESC => q{List declaration without trailing comma}; | |||||||||||||||||||||||||||
| 16 | 40 | Readonly::Scalar my $EXPL => [ 17 ]; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 90 | ▶ | sub supported_parameters { return () } | ||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | 74 | ▶ | sub default_severity { return $SEVERITY_LOWEST } | ||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 83 | ▶ | sub default_themes { return qw(core pbp cosmetic) } | ||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 31 | ▶ | sub applies_to { return 'PPI::Structure::List' } | ||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 22 | ▶ | sub violates { | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=10 SCAR=44.6
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 22 | my ( $self, $elem, undef ) = @_; | |||||||||||||||||||||||||||
| 29 | 22 | ▶ | $elem =~ m{ \n }xms || return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # Is it an assignment of some kind? | ||||||||||||||||||||||||||||
| 32 | 0 | my $sib = $elem->sprevious_sibling(); | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | return if !$sib; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | $sib->isa('PPI::Token::Operator') && $sib =~ m{ = }xms || return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$sib->isa("PPI::Token::Operator") and $sib =~ / = /msx
MC/DC0%0/2
$sib->isa("PPI::Token::Operator") and $sib =~ / = /msx
$sib->isa("PPI::Token::Operator")
$sib =~ / = /msx
Truth table0%0/3
A and B
A= $sib->isa("PPI::Token::Operator")B= $sib =~ / = /msx
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # List elements are children of an expression | ||||||||||||||||||||||||||||
| 37 | 0 | my $expr = $elem->schild(0); | |||||||||||||||||||||||||||
| 38 | 0 | ▶ | return if !$expr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # Does the list have more than 1 element? | ||||||||||||||||||||||||||||
| 41 | # This means list element, not PPI element. | ||||||||||||||||||||||||||||
| 42 | 0 | my @children = $expr->schildren(); | |||||||||||||||||||||||||||
| 43 | 0 | ▶ | return if 1 >= grep { $_->isa('PPI::Token::Operator') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_->isa('PPI::Token::Operator') && $_ eq $Perl::Critic::Policy::CodeLayout::RequireTrailingCommas::COMMA
MC/DC0%0/2
$_->isa('PPI::Token::Operator') && $_ eq $Perl::Critic::Policy::CodeLayout::RequireTrailingCommas::COMMA
$_->isa('PPI::Token::Operator')
$_ eq $Perl::Critic::Policy::CodeLayout::RequireTrailingCommas::COMMA
Truth table0%0/3
A && B
A= $_->isa('PPI::Token::Operator')B= $_ eq $Perl::Critic::Policy::CodeLayout::RequireTrailingCommas::COMMA
| |||||||||||||||||||||||||||||
| 44 | && $_ eq $COMMA } @children; | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # Is the final element a comma? | ||||||||||||||||||||||||||||
| 47 | 0 | my $final = $children[-1]; | |||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ( ! ($final->isa('PPI::Token::Operator') && $final eq $COMMA) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$final->isa("PPI::Token::Operator") and $final eq $Perl::Critic::Policy::CodeLayout::RequireTrailingCommas::COMMA
MC/DC0%0/2
$final->isa("PPI::Token::Operator") and $final eq $Perl::Critic::Policy::CodeLayout::RequireTrailingCommas::COMMA
$final->isa("PPI::Token::Operator")
$final eq $Perl::Critic::Policy::CodeLayout::RequireTrailingCommas::COMMA
Truth table0%0/3
A and B
A= $final->isa("PPI::Token::Operator")B= $final eq $Perl::Critic::Policy::CodeLayout::RequireTrailingCommas::COMMA
| |||||||||||||||||||||||||||||
| 49 | 0 | return $self->violation( $DESC, $EXPL, $elem ); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | return; #ok! | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 40 | 1; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||||||||||