line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::BuiltinFunctions::ProhibitComplexMappings; |
2
|
133
|
|
|
133
|
|
68219
|
use strict; |
|
133
|
|
|
|
|
183
|
|
|
133
|
|
|
|
|
3192
|
|
3
|
133
|
|
|
133
|
|
422
|
use warnings; |
|
133
|
|
|
|
|
168
|
|
|
133
|
|
|
|
|
2436
|
|
4
|
133
|
|
|
133
|
|
783
|
use Perl::Lint::Constants::Type; |
|
133
|
|
|
|
|
165
|
|
|
133
|
|
|
|
|
58616
|
|
5
|
133
|
|
|
133
|
|
582
|
use parent "Perl::Lint::Policy"; |
|
133
|
|
|
|
|
178
|
|
|
133
|
|
|
|
|
590
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
8
|
133
|
|
|
|
|
43893
|
DESC => 'Map blocks should have a single statement', |
9
|
|
|
|
|
|
|
EXPL => [113], |
10
|
133
|
|
|
133
|
|
6632
|
}; |
|
133
|
|
|
|
|
185
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub evaluate { |
13
|
6
|
|
|
6
|
0
|
13
|
my ($class, $file, $tokens, $src, $args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
6
|
|
100
|
|
|
30
|
my $max_statements = $args->{prohibit_complex_mappings}->{max_statements} || 1; |
16
|
6
|
50
|
|
|
|
15
|
if (--$max_statements < 0) { |
17
|
0
|
|
|
|
|
0
|
$max_statements = 0; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
6
|
|
|
|
|
9
|
my @violations; |
21
|
6
|
|
|
|
|
8
|
my $statements_num = 0; |
22
|
6
|
|
|
|
|
25
|
for (my $i = 0; my $token = $tokens->[$i]; $i++) { |
23
|
121
|
|
|
|
|
85
|
my $token_type = $token->{type}; |
24
|
121
|
|
|
|
|
85
|
my $token_data = $token->{data}; |
25
|
|
|
|
|
|
|
|
26
|
121
|
100
|
66
|
|
|
267
|
if ($token_type == BUILTIN_FUNC && $token_data eq 'map') { |
27
|
20
|
|
|
|
|
19
|
$token = $tokens->[++$i]; |
28
|
20
|
100
|
|
|
|
32
|
if ($token->{type} == LEFT_PAREN) { |
29
|
1
|
|
|
|
|
2
|
$token = $tokens->[++$i]; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
20
|
100
|
|
|
|
30
|
if ($token->{type} != LEFT_BRACE) { |
33
|
5
|
|
|
|
|
9
|
next; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
15
|
|
|
|
|
14
|
my $left_brace_num = 1; |
37
|
15
|
|
|
|
|
13
|
my $placed_semi_colon = 0; |
38
|
15
|
|
|
|
|
24
|
for ($i++; my $token = $tokens->[$i]; $i++) { |
39
|
98
|
|
|
|
|
68
|
$token_type = $token->{type}; |
40
|
98
|
100
|
|
|
|
263
|
if ($token_type == IF_STATEMENT) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
41
|
|
|
|
|
|
|
push @violations, { |
42
|
|
|
|
|
|
|
filename => $file, |
43
|
|
|
|
|
|
|
line => $token->{line}, |
44
|
1
|
|
|
|
|
3
|
description => DESC, |
45
|
|
|
|
|
|
|
explanation => EXPL, |
46
|
|
|
|
|
|
|
policy => __PACKAGE__, |
47
|
|
|
|
|
|
|
}; |
48
|
1
|
|
|
|
|
3
|
last; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
elsif ($token_type == DO) { # skip semi-colons that are in do statement |
51
|
1
|
|
|
|
|
5
|
$token = $tokens->[++$i]; |
52
|
1
|
50
|
|
|
|
4
|
if ($token->{type} == LEFT_BRACE) { |
53
|
1
|
|
|
|
|
2
|
my $left_brace_num = 1; |
54
|
1
|
|
|
|
|
4
|
for ($i++; my $token = $tokens->[$i]; $i++) { |
55
|
4
|
|
|
|
|
4
|
$token_type = $token->{type}; |
56
|
4
|
50
|
|
|
|
12
|
if ($token_type == LEFT_BRACE) { |
|
|
100
|
|
|
|
|
|
57
|
0
|
|
|
|
|
0
|
$left_brace_num++; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_BRACE) { |
60
|
1
|
50
|
|
|
|
4
|
last if --$left_brace_num <= 0; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
elsif ($token_type == SEMI_COLON) { |
66
|
11
|
|
|
|
|
12
|
my $next_token = $tokens->[$i+1]; |
67
|
11
|
|
|
|
|
13
|
my $next_token_type = $next_token->{type}; |
68
|
11
|
|
|
|
|
9
|
$statements_num++; |
69
|
11
|
100
|
33
|
|
|
49
|
if ($statements_num > $max_statements && ($left_brace_num != 1 || ($next_token_type && $next_token_type != RIGHT_BRACE))) { |
|
|
|
66
|
|
|
|
|
70
|
|
|
|
|
|
|
push @violations, { |
71
|
|
|
|
|
|
|
filename => $file, |
72
|
|
|
|
|
|
|
line => $token->{line}, |
73
|
7
|
|
|
|
|
30
|
description => DESC, |
74
|
|
|
|
|
|
|
explanation => EXPL, |
75
|
|
|
|
|
|
|
policy => __PACKAGE__, |
76
|
|
|
|
|
|
|
}; |
77
|
7
|
|
|
|
|
16
|
last; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
elsif ($token_type == LEFT_BRACE) { |
81
|
9
|
|
|
|
|
13
|
$left_brace_num++; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_BRACE) { |
84
|
16
|
100
|
|
|
|
40
|
last if --$left_brace_num <= 0; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
6
|
|
|
|
|
28
|
return \@violations; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|