line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions; |
2
|
133
|
|
|
133
|
|
70509
|
use strict; |
|
133
|
|
|
|
|
178
|
|
|
133
|
|
|
|
|
3186
|
|
3
|
133
|
|
|
133
|
|
403
|
use warnings; |
|
133
|
|
|
|
|
141
|
|
|
133
|
|
|
|
|
2408
|
|
4
|
133
|
|
|
133
|
|
781
|
use Perl::Lint::Constants::Type; |
|
133
|
|
|
|
|
138
|
|
|
133
|
|
|
|
|
62656
|
|
5
|
133
|
|
|
133
|
|
564
|
use parent "Perl::Lint::Policy"; |
|
133
|
|
|
|
|
171
|
|
|
133
|
|
|
|
|
560
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
8
|
133
|
|
|
|
|
43310
|
DESC => 'Found "%s" in condition for an "%s"', |
9
|
|
|
|
|
|
|
EXPL => [99], |
10
|
133
|
|
|
133
|
|
7112
|
}; |
|
133
|
|
|
|
|
181
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my %invalid_op_types = ( |
13
|
|
|
|
|
|
|
&NOT => '!', |
14
|
|
|
|
|
|
|
&ALPHABET_NOT => 'not', |
15
|
|
|
|
|
|
|
&STRING_NOT_EQUAL => 'ne', |
16
|
|
|
|
|
|
|
&NOT_EQUAL => '!=', |
17
|
|
|
|
|
|
|
&LESS => '<', |
18
|
|
|
|
|
|
|
&LESS_EQUAL => '<=', |
19
|
|
|
|
|
|
|
&GREATER => '>', |
20
|
|
|
|
|
|
|
&GREATER_EQUAL => '>=', |
21
|
|
|
|
|
|
|
&COMPARE => '<=>', |
22
|
|
|
|
|
|
|
&STRING_LESS => 'lt', |
23
|
|
|
|
|
|
|
&STRING_GREATER => 'gt', |
24
|
|
|
|
|
|
|
&STRING_LESS_EQUAL => 'le', |
25
|
|
|
|
|
|
|
&STRING_GREATER_EQUAL => 'ge', |
26
|
|
|
|
|
|
|
&STRING_COMPARE => 'cmp', |
27
|
|
|
|
|
|
|
®_NOT => '!~', |
28
|
|
|
|
|
|
|
&STRING_NOT_EQUAL => 'ne', |
29
|
|
|
|
|
|
|
&NOT_EQUAL => '!=', |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub evaluate { |
33
|
109
|
|
|
109
|
0
|
146
|
my ($class, $file, $tokens, $src, $args) = @_; |
34
|
|
|
|
|
|
|
|
35
|
109
|
|
|
|
|
116
|
my @violations; |
36
|
109
|
|
|
|
|
251
|
for (my $i = 0, my $token_type; my $token = $tokens->[$i]; $i++) { |
37
|
4163
|
|
|
|
|
2601
|
$token_type = $token->{type}; |
38
|
4163
|
100
|
100
|
|
|
12040
|
if ($token_type == UNLESS_STATEMENT || $token_type == UNTIL_STATEMENT) { |
39
|
110
|
|
|
|
|
101
|
my $control_structure = $token->{data}; |
40
|
|
|
|
|
|
|
|
41
|
110
|
50
|
|
|
|
179
|
$token = $tokens->[++$i] or last; |
42
|
110
|
100
|
|
|
|
161
|
if ($token->{type} != LEFT_PAREN) { |
43
|
54
|
|
|
|
|
64
|
for (; $token = $tokens->[$i]; $i++) { |
44
|
218
|
|
|
|
|
154
|
$token_type = $token->{type}; |
45
|
218
|
100
|
|
|
|
417
|
if ($token_type == SEMI_COLON) { |
|
|
100
|
|
|
|
|
|
46
|
54
|
|
|
|
|
49
|
last; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
elsif ($invalid_op_types{$token_type}) { |
49
|
|
|
|
|
|
|
push @violations, { |
50
|
|
|
|
|
|
|
filename => $file, |
51
|
|
|
|
|
|
|
line => $token->{line}, |
52
|
54
|
|
|
|
|
349
|
description => sprintf(DESC, $invalid_op_types{$token_type}, $control_structure), |
53
|
|
|
|
|
|
|
explanation => EXPL, |
54
|
|
|
|
|
|
|
policy => __PACKAGE__, |
55
|
|
|
|
|
|
|
}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
54
|
|
|
|
|
94
|
next; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
56
|
|
|
|
|
41
|
my $lpnum = 1; |
63
|
56
|
|
|
|
|
75
|
for ($i++; $token = $tokens->[$i]; $i++) { |
64
|
108
|
|
|
|
|
78
|
$token_type = $token->{type}; |
65
|
|
|
|
|
|
|
|
66
|
108
|
50
|
|
|
|
297
|
if ($token_type == LEFT_PAREN) { |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
67
|
0
|
|
|
|
|
0
|
$lpnum++; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_PAREN) { |
70
|
0
|
0
|
|
|
|
0
|
last if --$lpnum <= 0; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
elsif ($invalid_op_types{$token_type}) { |
73
|
|
|
|
|
|
|
push @violations, { |
74
|
|
|
|
|
|
|
filename => $file, |
75
|
|
|
|
|
|
|
line => $token->{line}, |
76
|
56
|
|
|
|
|
259
|
description => sprintf(DESC, $invalid_op_types{$token_type}, $control_structure), |
77
|
|
|
|
|
|
|
explanation => EXPL, |
78
|
|
|
|
|
|
|
policy => __PACKAGE__, |
79
|
|
|
|
|
|
|
}; |
80
|
56
|
|
|
|
|
135
|
last; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
109
|
|
|
|
|
325
|
return \@violations; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|