line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::BuiltinFunctions::ProhibitReverseSortBlock; |
2
|
134
|
|
|
134
|
|
67706
|
use strict; |
|
134
|
|
|
|
|
191
|
|
|
134
|
|
|
|
|
3110
|
|
3
|
134
|
|
|
134
|
|
449
|
use warnings; |
|
134
|
|
|
|
|
169
|
|
|
134
|
|
|
|
|
2591
|
|
4
|
134
|
|
|
134
|
|
810
|
use Perl::Lint::Constants::Type; |
|
134
|
|
|
|
|
175
|
|
|
134
|
|
|
|
|
59345
|
|
5
|
134
|
|
|
134
|
|
594
|
use parent "Perl::Lint::Policy"; |
|
134
|
|
|
|
|
181
|
|
|
134
|
|
|
|
|
597
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
8
|
134
|
|
|
|
|
34441
|
DESC => 'Forbid $b before $a in sort blocks', |
9
|
|
|
|
|
|
|
EXPL => [152], |
10
|
134
|
|
|
134
|
|
6495
|
}; |
|
134
|
|
|
|
|
181
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub evaluate { |
13
|
9
|
|
|
9
|
0
|
14
|
my ($class, $file, $tokens, $src, $args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
9
|
|
|
|
|
9
|
my @violations; |
16
|
9
|
|
|
|
|
28
|
for (my $i = 0; my $token = $tokens->[$i]; $i++) { |
17
|
279
|
|
|
|
|
194
|
my $token_type = $token->{type}; |
18
|
279
|
|
|
|
|
173
|
my $token_data = $token->{data}; |
19
|
|
|
|
|
|
|
|
20
|
279
|
100
|
100
|
|
|
568
|
if ($token_type == BUILTIN_FUNC && $token_data eq 'sort') { |
21
|
30
|
|
|
|
|
26
|
$token = $tokens->[++$i]; |
22
|
30
|
100
|
|
|
|
35
|
if ($token->{type} == LEFT_PAREN) { |
23
|
10
|
|
|
|
|
8
|
$token = $tokens->[++$i]; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
30
|
100
|
|
|
|
45
|
if ($token->{type} == LEFT_BRACE) { |
27
|
24
|
|
|
|
|
20
|
my $left_brace_num = 1; |
28
|
24
|
|
|
|
|
9
|
my $is_b_at_before_comparator = 0; |
29
|
24
|
|
|
|
|
36
|
for ($i++; $token = $tokens->[$i]; $i++) { |
30
|
306
|
|
|
|
|
194
|
$token_type = $token->{type}; |
31
|
306
|
|
|
|
|
224
|
$token_data = $token->{data}; |
32
|
306
|
100
|
100
|
|
|
1848
|
if ($token_type == COMPARE || $token_type == STRING_COMPARE) { |
|
|
100
|
100
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
33
|
31
|
100
|
|
|
|
51
|
if ($is_b_at_before_comparator) { |
34
|
|
|
|
|
|
|
push @violations, { |
35
|
|
|
|
|
|
|
filename => $file, |
36
|
|
|
|
|
|
|
line => $token->{line}, |
37
|
10
|
|
|
|
|
34
|
description => DESC, |
38
|
|
|
|
|
|
|
explanation => EXPL, |
39
|
|
|
|
|
|
|
policy => __PACKAGE__, |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
elsif ($token_type == LEFT_BRACE) { |
44
|
18
|
|
|
|
|
23
|
$left_brace_num++; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_BRACE) { |
47
|
42
|
100
|
|
|
|
89
|
last if --$left_brace_num <= 0; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
elsif ($token_type == VAR && $token_data eq '$b') { |
50
|
26
|
|
|
|
|
36
|
$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
|
|
|
|
|
13
|
$is_b_at_before_comparator = 0; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
9
|
|
|
|
|
30
|
return \@violations; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|