| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::ValuesAndExpressions::ProhibitLeadingZeros; |
|
2
|
133
|
|
|
133
|
|
69050
|
use strict; |
|
|
133
|
|
|
|
|
200
|
|
|
|
133
|
|
|
|
|
3136
|
|
|
3
|
133
|
|
|
133
|
|
433
|
use warnings; |
|
|
133
|
|
|
|
|
154
|
|
|
|
133
|
|
|
|
|
2432
|
|
|
4
|
133
|
|
|
133
|
|
768
|
use Perl::Lint::Constants::Type; |
|
|
133
|
|
|
|
|
158
|
|
|
|
133
|
|
|
|
|
56556
|
|
|
5
|
133
|
|
|
133
|
|
547
|
use parent "Perl::Lint::Policy"; |
|
|
133
|
|
|
|
|
151
|
|
|
|
133
|
|
|
|
|
553
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
|
8
|
133
|
|
|
|
|
51499
|
DESC => q{Don't allow any leading zeros at all. Otherwise builtins that deal with Unix permissions, e.g. chmod, don't get flagged.}, |
|
9
|
|
|
|
|
|
|
EXPL => [58], |
|
10
|
133
|
|
|
133
|
|
7201
|
}; |
|
|
133
|
|
|
|
|
170
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub evaluate { |
|
13
|
13
|
|
|
13
|
0
|
33
|
my ($class, $file, $tokens, $src, $args) = @_; |
|
14
|
|
|
|
|
|
|
|
|
15
|
13
|
|
|
|
|
16
|
my $is_strict; |
|
16
|
13
|
100
|
|
|
|
44
|
if (my $this_policies_arg = $args->{prohibit_leading_zeros}) { |
|
17
|
5
|
|
|
|
|
12
|
$is_strict = $this_policies_arg->{strict}; |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
13
|
|
|
|
|
18
|
my @violations; |
|
21
|
13
|
|
|
|
|
49
|
for (my $i = 0; my $token = $tokens->[$i]; $i++) { |
|
22
|
336
|
|
|
|
|
221
|
my $token_type = $token->{type}; |
|
23
|
336
|
|
|
|
|
238
|
my $token_data = $token->{data}; |
|
24
|
|
|
|
|
|
|
|
|
25
|
336
|
100
|
100
|
|
|
719
|
if (!$is_strict && $token_type == BUILTIN_FUNC) { |
|
26
|
|
|
|
|
|
|
# skip the first argument of chmod() |
|
27
|
10
|
100
|
|
|
|
19
|
if ($token_data eq 'chmod') { |
|
28
|
4
|
100
|
|
|
|
8
|
if ($tokens->[++$i]->{type} == LEFT_PAREN) { |
|
29
|
2
|
|
|
|
|
2
|
$i++; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
4
|
|
|
|
|
8
|
next; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# skip third argument of dbmopen() |
|
35
|
6
|
100
|
|
|
|
13
|
if ($token_data eq 'dbmopen') { |
|
36
|
2
|
100
|
|
|
|
5
|
if ($tokens->[++$i]->{type} == LEFT_PAREN) { |
|
37
|
1
|
|
|
|
|
2
|
$i++; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
3
|
my $comma_num = 0; |
|
41
|
2
|
|
|
|
|
6
|
for ($i++; $token = $tokens->[$i]; $i++) { |
|
42
|
6
|
|
|
|
|
5
|
$token_type = $token->{type}; |
|
43
|
|
|
|
|
|
|
|
|
44
|
6
|
50
|
|
|
|
10
|
if ($token_type == SEMI_COLON) { |
|
45
|
0
|
|
|
|
|
0
|
last; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
6
|
100
|
|
|
|
9
|
if ($token_type == COMMA) { |
|
49
|
4
|
|
|
|
|
3
|
$comma_num++; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
6
|
100
|
|
|
|
12
|
if ($comma_num == 2) { |
|
53
|
2
|
|
|
|
|
3
|
$i++; |
|
54
|
2
|
|
|
|
|
3
|
last; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
} |
|
57
|
2
|
|
|
|
|
4
|
next; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# skip second argument of mkdir() |
|
61
|
4
|
100
|
|
|
|
32
|
if ($token_data eq 'mkdir') { |
|
62
|
2
|
100
|
|
|
|
8
|
if ($tokens->[++$i]->{type} == LEFT_PAREN) { |
|
63
|
1
|
|
|
|
|
1
|
$i++; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
2
|
|
|
|
|
3
|
my $comma_num = 0; |
|
67
|
2
|
|
|
|
|
5
|
for ($i++; $token = $tokens->[$i]; $i++) { |
|
68
|
2
|
|
|
|
|
3
|
$token_type = $token->{type}; |
|
69
|
|
|
|
|
|
|
|
|
70
|
2
|
50
|
|
|
|
4
|
if ($token_type == SEMI_COLON) { |
|
71
|
0
|
|
|
|
|
0
|
last; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
2
|
50
|
|
|
|
5
|
if ($token_type == COMMA) { |
|
75
|
2
|
|
|
|
|
2
|
$comma_num++; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
2
|
50
|
|
|
|
4
|
if ($comma_num == 1) { |
|
79
|
2
|
|
|
|
|
3
|
$i++; |
|
80
|
2
|
|
|
|
|
2
|
last; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
} |
|
83
|
2
|
|
|
|
|
5
|
next; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# skip the first argument of umask() |
|
87
|
2
|
50
|
|
|
|
10
|
if ($token_data eq 'umask') { |
|
88
|
2
|
100
|
|
|
|
7
|
if ($tokens->[++$i]->{type} == LEFT_PAREN) { |
|
89
|
1
|
|
|
|
|
2
|
$i++; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
2
|
|
|
|
|
7
|
next; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
326
|
100
|
100
|
|
|
656
|
if (!$is_strict && $token_type == KEY) { |
|
96
|
|
|
|
|
|
|
# skip the fourth argument of sysopen() |
|
97
|
3
|
50
|
|
|
|
7
|
if ($token_data eq 'sysopen') { |
|
98
|
3
|
100
|
|
|
|
8
|
if ($tokens->[++$i]->{type} == LEFT_PAREN) { |
|
99
|
2
|
|
|
|
|
3
|
$i++; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
3
|
|
|
|
|
3
|
my $comma_num = 0; |
|
103
|
3
|
|
|
|
|
7
|
for ($i++; $token = $tokens->[$i]; $i++) { |
|
104
|
25
|
|
|
|
|
15
|
$token_type = $token->{type}; |
|
105
|
|
|
|
|
|
|
|
|
106
|
25
|
50
|
|
|
|
32
|
if ($token_type == SEMI_COLON) { |
|
107
|
0
|
|
|
|
|
0
|
last; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
25
|
100
|
|
|
|
27
|
if ($token_type == COMMA) { |
|
111
|
9
|
|
|
|
|
6
|
$comma_num++; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
25
|
100
|
|
|
|
44
|
if ($comma_num == 3) { |
|
115
|
3
|
|
|
|
|
3
|
$i++; |
|
116
|
3
|
|
|
|
|
2
|
last; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
} |
|
119
|
3
|
|
|
|
|
7
|
next; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
323
|
100
|
|
|
|
594
|
if ($token_type == INT) { |
|
124
|
37
|
|
|
|
|
40
|
my $int = $token_data; |
|
125
|
37
|
|
|
|
|
43
|
$int =~ s/_//g; |
|
126
|
37
|
100
|
50
|
|
|
1484
|
if ($int =~ /\A-?0/ && (eval($int) // 0) != 0) { ## no critic: to accept bin, oct and hex decimal |
|
|
|
|
100
|
|
|
|
|
|
127
|
|
|
|
|
|
|
push @violations, { |
|
128
|
|
|
|
|
|
|
filename => $file, |
|
129
|
|
|
|
|
|
|
line => $token->{line}, |
|
130
|
30
|
|
|
|
|
111
|
description => DESC, |
|
131
|
|
|
|
|
|
|
explanation => EXPL, |
|
132
|
|
|
|
|
|
|
policy => __PACKAGE__, |
|
133
|
|
|
|
|
|
|
}; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
37
|
|
|
|
|
110
|
next; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
|
|
139
|
13
|
|
|
|
|
57
|
return \@violations; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |
|
143
|
|
|
|
|
|
|
|