Perl/Lint/Policy/ValuesAndExpressions/ProhibitCommaSeparatedStatements.pm

filter: Statementstmt 19.3% 19 / 98 Branchbran 0.0% 0 / 82 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 1 totaltotal 11.2% 25 / 222 CC 49 SCAR 76.9
CC
49
Cov
9%
evaluate
2450.0
BEGIN
1.0
BEGIN
1.0
CRAP 2182.8
« Perl/Lint/Policy/RegularExpressions/ProhibitCaptureWithoutTest.pm ↑ Summary Perl/Lint/Policy/InputOutput/RequireCheckedSyscalls.pm »
1 package Perl::Lint::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Perl::Lint::Keywords;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 DESC => 'Comma used to separate statements',
10 EXPL => [68, 71],
11 2 };
12  
13 0 ▶sub evaluate {
Subroutine evaluate: not called CC=49 SCAR=78.0
Pod undocumented
14 0 my ($class, $file, $tokens, $src, $args) = @_;
15  
16 0 my $allow_last_statement_to_be_comma_separated_in_map_and_grep;
17 0 ▶ if (my $this_policies_arg = $args->{prohibit_comma_separated_statements}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $this_policies_arg = $args->{"prohibit_comma_separated_statements"}) 0 0 0
18 0 $allow_last_statement_to_be_comma_separated_in_map_and_grep = $this_policies_arg->{allow_last_statement_to_be_comma_separated_in_map_and_grep};
19 }
20  
21 0 my @violations;
22 0 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
23 0 my $token_type = $token->{type};
24  
25 0 ▶ if ($token_type == ASSIGN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 65) { } 0 0 0
elsif ($token_type == 133) { } 0 0 0
26 0 $token = $tokens->[++$i];
27 0 $token_type = $token->{type};
28  
29 # if rvalues are surrounded by parans, theres are no problem
30 0 ▶ if ($token_type != LEFT_PAREN && $token_type != LEFT_BRACE && $token_type != LEFT_BRACKET) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type != 107 and $token_type != 109 and $token_type != 111) { } 0 0 0
Condition0%0/6
$token_type != 107 and $token_type != 109 and $token_type != 111
!ll&&!rl&&r
000
$token_type != 107 and $token_type != 109
!ll&&!rl&&r
000
MC/DC0%0/3
$token_type != 107 and $token_type != 109 and $token_type != 111
$token_type != 107 $token_type != 109 $token_type != 111
Truth table0%0/4
A and B and C
A= $token_type != 107B= $token_type != 109C= $token_type != 111
ABCresult
0XX0
10X0
1100
1111
31 0 my $does_comma_exist = 0;
32  
33 ONE_LINE:
34 0 ▶ for (; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
35 0 $token_type = $token->{type};
36  
37 0 ▶ if ($token_type == COMMA) {
Branch: 3 branches
BranchTrueFalseTotal
if ($token_type == 104) { } 0 0 0
elsif ($token_type == 106) { } 0 0 0
elsif ($token_type == 122 or $token_type == 70) { } 0 0 0
38 0 $does_comma_exist = 1;
39 }
40 elsif ($token_type == SEMI_COLON) {
41 0 last;
42 }
43 ▶ elsif ($token_type == KEY || $token_type == BUILTIN_FUNC) {
Condition0%0/3
$token_type == 122 or $token_type == 70
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 122 or $token_type == 70
$token_type == 122 $token_type == 70
Truth table0%0/3
A or B
A= $token_type == 122B= $token_type == 70
ABresult
1X1
011
000
44 0 my $token_data = $token->{data};
45 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 70 and is_perl_builtin_which_take_multiple_arguments($token_data)) 0 0 0
Condition0%0/3
$token_type == 70 and is_perl_builtin_which_take_multiple_arguments($token_data)
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 70 and is_perl_builtin_which_take_multiple_arguments($token_data)
$token_type == 70 is_perl_builtin_which_take_multiple_arguments($token_data)
Truth table0%0/3
A and B
A= $token_type == 70B= is_perl_builtin_which_take_multiple_arguments($token_data)
ABresult
0X0
100
111
46 $token_type == BUILTIN_FUNC &&
47 is_perl_builtin_which_take_multiple_arguments($token_data)
48 ) {
49 0 ▶ my $is_map_or_grep = ($token_data eq 'map' || $token_data eq 'grep') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$token_data eq 'map' || $token_data eq 'grep' ? : 0 0 0
Condition0%0/3
$token_data eq "map" or $token_data eq "grep"
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_data eq "map" or $token_data eq "grep"
$token_data eq "map" $token_data eq "grep"
Truth table0%0/3
A or B
A= $token_data eq "map"B= $token_data eq "grep"
ABresult
1X1
011
000
50  
51 0 my $next_token = $tokens->[$i+1];
52 0 my $next_token_type = $next_token->{type};
53 0 ▶ if ($next_token_type == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token_type == 107) { } 0 0 0
54 0 my $left_paren_num = 1;
55 0 ▶ for ($i+=2; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
56 0 $token_type = $token->{type};
57 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 108) { } 0 0 0
58 0 $left_paren_num++;
59 }
60 elsif ($token_type == RIGHT_PAREN) {
61 0 ▶ last if --$left_paren_num <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$left_paren_num <= 0 0 0 0
62 }
63 }
64 }
65 else {
66 0 my $left_brace_num = 0;
67  
68 0 ▶ if ($is_map_or_grep && !$allow_last_statement_to_be_comma_separated_in_map_and_grep) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_map_or_grep and not $allow_last_statement_to_be_comma_separated_in_map_and_grep) 0 0 0
Condition0%0/3
$is_map_or_grep and not $allow_last_statement_to_be_comma_separated_in_map_and_grep
!ll&&!rl&&r
000
MC/DC0%0/2
$is_map_or_grep and not $allow_last_statement_to_be_comma_separated_in_map_and_grep
$is_map_or_grep not $allow_last_statement_to_be_comma_separated_in_map_and_grep
Truth table0%0/3
A and not(B)
A= $is_map_or_grepB= not $allow_last_statement_to_be_comma_separated_in_map_and_grep
ABresult
0X0
100
111
69 0 ▶ for (; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
70 0 $token_type = $token->{type};
71  
72 0 ▶ if ($token_type == LEFT_BRACE) {
Branch: 3 branches
BranchTrueFalseTotal
if ($token_type == 109) { } 0 0 0
elsif ($token_type == 110) { } 0 0 0
elsif ($token_type == 104) { } 0 0 0
73 0 $left_brace_num++;
74 }
75 elsif ($token_type == RIGHT_BRACE) {
76 0 ▶ last if --$left_brace_num <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$left_brace_num <= 0 0 0 0
77 }
78 elsif ($token_type == COMMA) {
79 0 my $next_token = $tokens->[$i+1];
80 0 my $next_token_type = $next_token->{type};
81 0 ▶ if ($next_token_type != KEY) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token_type != 122) 0 0 0
82 0 $does_comma_exist = 1;
83 }
84 }
85 }
86 0 $i++;
87 }
88  
89 0 ▶ for (; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
90 0 $token_type = $token->{type};
91 0 ▶ if ($token_type == SEMI_COLON) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 106) 0 0 0
92 0 last ONE_LINE;
93 }
94 }
95 }
96 }
97  
98 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
99 0 $token_type = $token->{type};
100 0 ▶ if ($token_type == COMMA) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 104) { } 0 0 0
elsif ($token_type == 106) { } 0 0 0
101 0 my $next_token = $tokens->[$i+1];
102 0 my $next_token_type = $next_token->{type};
103 0 ▶ if ($next_token_type != KEY) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token_type != 122) 0 0 0
104 0 $does_comma_exist = 1;
105 }
106  
107 0 last;
108 }
109 elsif ($token_type == SEMI_COLON) {
110 0 last ONE_LINE;
111 }
112 }
113 }
114 }
115  
116 0 ▶ if ($does_comma_exist) {
Branch: 1 branch
BranchTrueFalseTotal
if ($does_comma_exist) 0 0 0
117 push @violations, {
118 filename => $file,
119 line => $token->{line}, # TODO
120 0 description => DESC,
121 explanation => EXPL,
122 policy => __PACKAGE__,
123 };
124 }
125 }
126 else {
127 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
128 0 $token_type = $token->{type};
129  
130 0 ▶ if ($token_type == SEMI_COLON) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 106) 0 0 0
131 0 last;
132 }
133 }
134 }
135 }
136 elsif ($token_type == FOR_STATEMENT) {
137 0 my $next_token = $tokens->[$i+1];
138  
139 0 ▶ if ($next_token->{type} != LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token->{"type"} != 107) 0 0 0
140 0 next;
141 }
142  
143 0 my $left_paren_num = 1;
144 0 my $does_comma_exist = 0;
145 0 my $is_semi_colon_in_paren = 0; # XXX
146 0 ▶ for ($i+=2; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
147 0 $token_type = $token->{type};
148  
149 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_type == 104) { } 0 0 0
elsif ($token_type == 106) { } 0 0 0
150 0 $left_paren_num++;
151 }
152 elsif ($token_type == RIGHT_PAREN) {
153 0 ▶ if ($does_comma_exist && $is_semi_colon_in_paren) {
Branch: 1 branch
BranchTrueFalseTotal
if ($does_comma_exist and $is_semi_colon_in_paren) 0 0 0
Condition0%0/3
$does_comma_exist and $is_semi_colon_in_paren
!ll&&!rl&&r
000
MC/DC0%0/2
$does_comma_exist and $is_semi_colon_in_paren
$does_comma_exist $is_semi_colon_in_paren
Truth table0%0/3
A and B
A= $does_comma_existB= $is_semi_colon_in_paren
ABresult
0X0
100
111
154 push @violations, {
155 filename => $file,
156 line => $token->{line}, # TODO
157 0 description => DESC,
158 explanation => EXPL,
159 policy => __PACKAGE__,
160 };
161 }
162  
163 0 ▶ last if --$left_paren_num <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$left_paren_num <= 0 0 0 0
164 }
165 elsif ($token_type == COMMA) {
166 0 $does_comma_exist = 1;
167 }
168 elsif ($token_type == SEMI_COLON) {
169 0 ▶ if ($does_comma_exist) {
Branch: 1 branch
BranchTrueFalseTotal
if ($does_comma_exist) 0 0 0
170 push @violations, {
171 filename => $file,
172 line => $token->{line}, # TODO
173 0 description => DESC,
174 explanation => EXPL,
175 policy => __PACKAGE__,
176 };
177 }
178 0 $is_semi_colon_in_paren = 1;
179 0 $does_comma_exist = 0;
180 }
181 }
182 }
183 }
184  
185 0 return \@violations;
186 }
187  
188 2 1;
189  
« Perl/Lint/Policy/RegularExpressions/ProhibitCaptureWithoutTest.pm ↑ Summary Perl/Lint/Policy/InputOutput/RequireCheckedSyscalls.pm »