Perl/Lint/Policy/CodeLayout/RequireTrailingCommas.pm

filter: Statementstmt 56.2% 27 / 48 Branchbran 22.7% 5 / 22 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 41.0% 39 / 95 CC 16 SCAR 46.5
CC
16
Cov
39%
evaluate
144.0
BEGIN
1.0
BEGIN
1.0
CRAP 105.0
« Perl/Lint/Policy/ControlStructures/ProhibitCascadingIfElse.pm ↑ Summary Perl/Lint/Policy/ValuesAndExpressions/ProhibitInterpolationOfLiterals.pm »
1 package Perl::Lint::Policy::CodeLayout::RequireTrailingCommas;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Perl::Lint::Constants::Kind;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 DESC => 'List declaration without trailing comma',
10 EXPL => [17],
11 3 };
12  
13 2 ▶sub evaluate {
Subroutine evaluate: called CC=16 SCAR=49.7
Pod undocumented
14 2 my ($class, $file, $tokens, $src, $args) = @_;
15  
16 2 my @violations;
17 2 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 50 2 52
18 50 my $token_type = $token->{type};
19  
20 50 ▶ if ($token_type == ASSIGN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 65) 1 49 50
21 1 $token = $tokens->[++$i];
22  
23 1 ▶ if ($token->{type} == LEFT_PAREN) { # TODO enough?
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} == 107) 0 1 1
24 0 my $begin_line = $token->{line};
25  
26 0 my $left_paren_num = 1;
27 0 my $num_of_item = 0;
28 0 my $is_nested = 0;
29 0 my $does_exist_procedure = 0;
30 0 my $does_exist_any_comma = 0;
31  
32 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
33 0 $token_type = $token->{type};
34  
35 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 4 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 108) { } 0 0 0
elsif ($token->{'kind'} == 1) { } 0 0 0
elsif ($token_type == 104) { } 0 0 0
36 0 $left_paren_num++;
37 0 $is_nested = 1;
38 }
39 elsif ($token_type == RIGHT_PAREN) {
40 0 ▶ if (--$left_paren_num <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$left_paren_num <= 0) 0 0 0
41 0 my $end_line = $token->{line};
42 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not $is_nested and !$does_exist_procedure || $does_exist_any_comma and $num_of_item > 1 and $end_line - $begin_line > 0) 0 0 0
Condition0%0/12
not $is_nested and !$does_exist_procedure || $does_exist_any_comma and $num_of_item > 1 and $end_line - $begin_line > 0
!ll&&!rl&&r
000
not $is_nested and !$does_exist_procedure || $does_exist_any_comma and $num_of_item > 1
!ll&&!rl&&r
000
not $is_nested and !$does_exist_procedure || $does_exist_any_comma
!ll&&!rl&&r
000
not $does_exist_procedure or $does_exist_any_comma
l!l&&r!l&&!r
000
MC/DC0%0/5
not $is_nested and !$does_exist_procedure || $does_exist_any_comma and $num_of_item > 1 and $end_line - $begin_line > 0
not $is_nested not $does_exist_procedure $does_exist_any_comma $num_of_item > 1 $end_line - $begin_line > 0
Truth table0%0/8
not(A) and not(B) or C and D and E
A= not $is_nestedB= not $does_exist_procedureC= $does_exist_any_commaD= $num_of_item > 1E= $end_line - $begin_line > 0
ABCDEresult
0XXXX0
100XX0
11X0X0
1010X0
11X100
101100
11X111
101111
43 !$is_nested &&
44 (!$does_exist_procedure || $does_exist_any_comma) &&
45 $num_of_item > 1 &&
46 $end_line - $begin_line > 0
47 ) {
48 0 my $just_before_token = $tokens->[$i-1];
49 0 ▶ if ($just_before_token->{type} != COMMA) {
Branch: 1 branch
BranchTrueFalseTotal
if ($just_before_token->{"type"} != 104) 0 0 0
50 push @violations, {
51 filename => $file,
52 line => $token->{line},
53 0 description => DESC,
54 explanation => EXPL,
55 policy => __PACKAGE__,
56 };
57 }
58 }
59  
60 0 last;
61 }
62 }
63 elsif (
64 $token->{kind} == KIND_OP
65 ) {
66 0 $does_exist_procedure = 1;
67 }
68 elsif ($token_type == COMMA) {
69 0 $does_exist_any_comma = 1;
70 }
71 else {
72 0 $num_of_item++;
73 }
74 }
75 }
76 }
77 }
78  
79 2 return \@violations;
80 }
81  
82 3 1;
83  
« Perl/Lint/Policy/ControlStructures/ProhibitCascadingIfElse.pm ↑ Summary Perl/Lint/Policy/ValuesAndExpressions/ProhibitInterpolationOfLiterals.pm »