line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::ControlStructures::ProhibitCStyleForLoops; |
2
|
134
|
|
|
134
|
|
92477
|
use strict; |
|
134
|
|
|
|
|
265
|
|
|
134
|
|
|
|
|
5162
|
|
3
|
134
|
|
|
134
|
|
632
|
use warnings; |
|
134
|
|
|
|
|
199
|
|
|
134
|
|
|
|
|
3339
|
|
4
|
134
|
|
|
134
|
|
1014
|
use Perl::Lint::Constants::Type; |
|
134
|
|
|
|
|
231
|
|
|
134
|
|
|
|
|
82663
|
|
5
|
134
|
|
|
134
|
|
1310
|
use Perl::Lint::Constants::Kind; |
|
134
|
|
|
|
|
227
|
|
|
134
|
|
|
|
|
8885
|
|
6
|
134
|
|
|
134
|
|
657
|
use parent "Perl::Lint::Policy"; |
|
134
|
|
|
|
|
200
|
|
|
134
|
|
|
|
|
814
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use constant { |
9
|
134
|
|
|
|
|
36360
|
DESC => 'C-style "for" loop used', |
10
|
|
|
|
|
|
|
EXPL => [100], |
11
|
134
|
|
|
134
|
|
8626
|
}; |
|
134
|
|
|
|
|
221
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub evaluate { |
14
|
5
|
|
|
5
|
0
|
10
|
my ($class, $file, $tokens, $src, $args) = @_; |
15
|
|
|
|
|
|
|
|
16
|
5
|
|
|
|
|
9
|
my @violations; |
17
|
5
|
|
|
|
|
24
|
for (my $i = 0; my $token = $tokens->[$i]; $i++) { |
18
|
114
|
|
|
|
|
81
|
my $token_type = $token->{type}; |
19
|
|
|
|
|
|
|
|
20
|
114
|
100
|
100
|
|
|
391
|
if ($token_type == FOR_STATEMENT || $token_type == FOREACH_STATEMENT) { |
21
|
11
|
|
|
|
|
12
|
my $token = $tokens->[++$i]; |
22
|
11
|
100
|
|
|
|
27
|
if ($token->{type} == LEFT_PAREN) { |
23
|
8
|
|
|
|
|
9
|
my $semi_colon_count = 0; |
24
|
8
|
|
|
|
|
8
|
my $left_paren_num = 1; |
25
|
8
|
|
|
|
|
21
|
for ($i++; my $token = $tokens->[$i]; $i++) { |
26
|
80
|
|
|
|
|
59
|
my $token_type = $token->{type}; |
27
|
80
|
50
|
|
|
|
208
|
if ($token_type == LEFT_PAREN) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
28
|
0
|
|
|
|
|
0
|
$left_paren_num++; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_PAREN) { |
31
|
8
|
50
|
|
|
|
19
|
last if --$left_paren_num <= 0; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
elsif ($token_type == SEMI_COLON) { |
34
|
14
|
|
|
|
|
26
|
$semi_colon_count++; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
8
|
100
|
|
|
|
16
|
if ($semi_colon_count == 2) { |
39
|
7
|
|
|
|
|
42
|
push @violations, { |
40
|
|
|
|
|
|
|
filename => $file, |
41
|
|
|
|
|
|
|
line => $token->{line}, |
42
|
|
|
|
|
|
|
description => DESC, |
43
|
|
|
|
|
|
|
explanation => EXPL, |
44
|
|
|
|
|
|
|
policy => __PACKAGE__, |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
5
|
|
|
|
|
19
|
return \@violations; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
|