line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::BuiltinFunctions::ProhibitReverseSortBlock; |
2
|
134
|
|
|
134
|
|
67872
|
use strict; |
|
134
|
|
|
|
|
194
|
|
|
134
|
|
|
|
|
3255
|
|
3
|
134
|
|
|
134
|
|
425
|
use warnings; |
|
134
|
|
|
|
|
168
|
|
|
134
|
|
|
|
|
2545
|
|
4
|
134
|
|
|
134
|
|
789
|
use Perl::Lint::Constants::Type; |
|
134
|
|
|
|
|
179
|
|
|
134
|
|
|
|
|
59021
|
|
5
|
134
|
|
|
134
|
|
599
|
use parent "Perl::Lint::Policy"; |
|
134
|
|
|
|
|
185
|
|
|
134
|
|
|
|
|
588
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
8
|
134
|
|
|
|
|
34847
|
DESC => 'Forbid $b before $a in sort blocks', |
9
|
|
|
|
|
|
|
EXPL => [152], |
10
|
134
|
|
|
134
|
|
6705
|
}; |
|
134
|
|
|
|
|
175
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub evaluate { |
13
|
9
|
|
|
9
|
0
|
14
|
my ($class, $file, $tokens, $src, $args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
9
|
|
|
|
|
8
|
my @violations; |
16
|
9
|
|
|
|
|
29
|
for (my $i = 0; my $token = $tokens->[$i]; $i++) { |
17
|
279
|
|
|
|
|
162
|
my $token_type = $token->{type}; |
18
|
279
|
|
|
|
|
186
|
my $token_data = $token->{data}; |
19
|
|
|
|
|
|
|
|
20
|
279
|
100
|
100
|
|
|
580
|
if ($token_type == BUILTIN_FUNC && $token_data eq 'sort') { |
21
|
30
|
|
|
|
|
24
|
$token = $tokens->[++$i]; |
22
|
30
|
100
|
|
|
|
42
|
if ($token->{type} == LEFT_PAREN) { |
23
|
10
|
|
|
|
|
9
|
$token = $tokens->[++$i]; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
30
|
100
|
|
|
|
42
|
if ($token->{type} == LEFT_BRACE) { |
27
|
24
|
|
|
|
|
11
|
my $left_brace_num = 1; |
28
|
24
|
|
|
|
|
21
|
my $is_b_at_before_comparator = 0; |
29
|
24
|
|
|
|
|
32
|
for ($i++; $token = $tokens->[$i]; $i++) { |
30
|
306
|
|
|
|
|
204
|
$token_type = $token->{type}; |
31
|
306
|
|
|
|
|
228
|
$token_data = $token->{data}; |
32
|
306
|
100
|
100
|
|
|
1876
|
if ($token_type == COMPARE || $token_type == STRING_COMPARE) { |
|
|
100
|
100
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
33
|
31
|
100
|
|
|
|
54
|
if ($is_b_at_before_comparator) { |
34
|
|
|
|
|
|
|
push @violations, { |
35
|
|
|
|
|
|
|
filename => $file, |
36
|
|
|
|
|
|
|
line => $token->{line}, |
37
|
10
|
|
|
|
|
37
|
description => DESC, |
38
|
|
|
|
|
|
|
explanation => EXPL, |
39
|
|
|
|
|
|
|
policy => __PACKAGE__, |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
elsif ($token_type == LEFT_BRACE) { |
44
|
18
|
|
|
|
|
24
|
$left_brace_num++; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_BRACE) { |
47
|
42
|
100
|
|
|
|
93
|
last if --$left_brace_num <= 0; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
elsif ($token_type == VAR && $token_data eq '$b') { |
50
|
26
|
|
|
|
|
37
|
$is_b_at_before_comparator = 1; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
elsif ( # XXX enough? |
53
|
|
|
|
|
|
|
$token_type == OR || |
54
|
|
|
|
|
|
|
$token_type == AND || |
55
|
|
|
|
|
|
|
$token_type == ALPHABET_OR || |
56
|
|
|
|
|
|
|
$token_type == ALPHABET_AND |
57
|
|
|
|
|
|
|
) { |
58
|
7
|
|
|
|
|
10
|
$is_b_at_before_comparator = 0; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
9
|
|
|
|
|
29
|
return \@violations; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|