blib/lib/Perl/Lint/Policy/CodeLayout/RequireTrailingCommas.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 SCAR 0.1
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Perl/Lint/Policy/CodeLayout/ProhibitQuotedWordLists.pm ↑ Summary blib/lib/Perl/Lint/Policy/ControlStructures/ProhibitCStyleForLoops.pm »
1 package Perl::Lint::Policy::CodeLayout::RequireTrailingCommas;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=2.6
5 use Perl::Lint::Constants::Kind;
6 use parent "Perl::Lint::Policy";
7  
8 use constant {
9 DESC => 'List declaration without trailing comma',
10 EXPL => [17],
11 };
12  
13 sub evaluate {
14 my ($class, $file, $tokens, $src, $args) = @_;
15  
16 my @violations;
17 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
18 my $token_type = $token->{type};
19  
20 if ($token_type == ASSIGN) {
21 $token = $tokens->[++$i];
22  
23 if ($token->{type} == LEFT_PAREN) { # TODO enough?
24 my $begin_line = $token->{line};
25  
26 my $left_paren_num = 1;
27 my $num_of_item = 0;
28 my $is_nested = 0;
29 my $does_exist_procedure = 0;
30 my $does_exist_any_comma = 0;
31  
32 for ($i++; $token = $tokens->[$i]; $i++) {
33 $token_type = $token->{type};
34  
35 if ($token_type == LEFT_PAREN) {
36 $left_paren_num++;
37 $is_nested = 1;
38 }
39 elsif ($token_type == RIGHT_PAREN) {
40 if (--$left_paren_num <= 0) {
41 my $end_line = $token->{line};
42 if (
43 !$is_nested &&
44 (!$does_exist_procedure || $does_exist_any_comma) &&
45 $num_of_item > 1 &&
46 $end_line - $begin_line > 0
47 ) {
48 my $just_before_token = $tokens->[$i-1];
49 if ($just_before_token->{type} != COMMA) {
50 push @violations, {
51 filename => $file,
52 line => $token->{line},
53 description => DESC,
54 explanation => EXPL,
55 policy => __PACKAGE__,
56 };
57 }
58 }
59  
60 last;
61 }
62 }
63 elsif (
64 $token->{kind} == KIND_OP
65 ) {
66 $does_exist_procedure = 1;
67 }
68 elsif ($token_type == COMMA) {
69 $does_exist_any_comma = 1;
70 }
71 else {
72 $num_of_item++;
73 }
74 }
75 }
76 }
77 }
78  
79 return \@violations;
80 }
81  
82 1;
83  
« blib/lib/Perl/Lint/Policy/CodeLayout/ProhibitQuotedWordLists.pm ↑ Summary blib/lib/Perl/Lint/Policy/ControlStructures/ProhibitCStyleForLoops.pm »