line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::Subroutines::ProhibitReturnSort; |
2
|
133
|
|
|
133
|
|
70860
|
use strict; |
|
133
|
|
|
|
|
197
|
|
|
133
|
|
|
|
|
3215
|
|
3
|
133
|
|
|
133
|
|
433
|
use warnings; |
|
133
|
|
|
|
|
176
|
|
|
133
|
|
|
|
|
2533
|
|
4
|
133
|
|
|
133
|
|
839
|
use Perl::Lint::Constants::Type; |
|
133
|
|
|
|
|
166
|
|
|
133
|
|
|
|
|
59139
|
|
5
|
133
|
|
|
133
|
|
588
|
use parent "Perl::Lint::Policy"; |
|
133
|
|
|
|
|
186
|
|
|
133
|
|
|
|
|
589
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
8
|
133
|
|
|
|
|
42375
|
DESC => '"return" statement followed by "sort"', |
9
|
|
|
|
|
|
|
EXPL => 'Behavior is undefined if called in scalar context', |
10
|
133
|
|
|
133
|
|
6752
|
}; |
|
133
|
|
|
|
|
208
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub evaluate { |
13
|
5
|
|
|
5
|
0
|
7
|
my ($class, $file, $tokens, $args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
5
|
|
|
|
|
5
|
my @violations; |
16
|
5
|
|
|
|
|
16
|
for (my $i = 0; my $token = $tokens->[$i]; $i++) { |
17
|
96
|
|
|
|
|
70
|
my $token_type = $token->{type}; |
18
|
|
|
|
|
|
|
|
19
|
96
|
100
|
|
|
|
187
|
if ($token_type == RETURN) { |
|
|
100
|
|
|
|
|
|
20
|
17
|
|
|
|
|
14
|
my $next_token = $tokens->[$i+1]; |
21
|
17
|
100
|
100
|
|
|
64
|
if ($next_token->{type} == BUILTIN_FUNC && $next_token->{data} eq 'sort') { |
22
|
13
|
|
|
|
|
11
|
my $is_in_postposition_if = 0; |
23
|
13
|
|
|
|
|
8
|
my $is_wantarray = 0; |
24
|
13
|
|
|
|
|
21
|
for ($i++; my $token = $tokens->[$i]; $i++) { |
25
|
81
|
|
|
|
|
56
|
my $token_type = $token->{type}; |
26
|
81
|
100
|
100
|
|
|
231
|
if ($token_type == SEMI_COLON) { |
|
|
100
|
66
|
|
|
|
|
|
|
100
|
|
|
|
|
|
27
|
13
|
100
|
|
|
|
16
|
if (!$is_wantarray) { |
28
|
|
|
|
|
|
|
push @violations, { |
29
|
|
|
|
|
|
|
filename => $file, |
30
|
|
|
|
|
|
|
line => $token->{line}, |
31
|
12
|
|
|
|
|
32
|
description => DESC, |
32
|
|
|
|
|
|
|
explanation => EXPL, |
33
|
|
|
|
|
|
|
policy => __PACKAGE__, |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
} |
36
|
13
|
|
|
|
|
13
|
last; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
elsif ($token_type == IF_STATEMENT) { |
39
|
5
|
|
|
|
|
7
|
$is_in_postposition_if = 1; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
elsif ($token_type == BUILTIN_FUNC && $token->{data} eq 'wantarray' && $is_in_postposition_if) { |
42
|
1
|
|
|
|
|
2
|
$is_wantarray = 1; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
13
|
|
|
|
|
18
|
next; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
elsif ($token_type == IF_STATEMENT) { |
49
|
1
|
|
|
|
|
2
|
my $left_brace_num = 0; |
50
|
1
|
|
|
|
|
2
|
my $is_wantarray = 0; |
51
|
1
|
|
|
|
|
4
|
for ($i++; my $token = $tokens->[$i]; $i++) { |
52
|
9
|
|
|
|
|
8
|
my $token_type = $token->{type}; |
53
|
9
|
100
|
100
|
|
|
33
|
if ($token_type == LEFT_BRACE) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
54
|
1
|
|
|
|
|
2
|
$left_brace_num++; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_BRACE) { |
57
|
1
|
|
|
|
|
2
|
$left_brace_num--; |
58
|
1
|
50
|
|
|
|
5
|
last if ($left_brace_num <= 0); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
elsif ($token_type == BUILTIN_FUNC && $token->{data} eq 'wantarray') { |
61
|
1
|
|
|
|
|
2
|
$is_wantarray = 1; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
elsif (!$is_wantarray) { |
64
|
1
|
|
|
|
|
2
|
my $next_token = $tokens->[$i+1]; |
65
|
1
|
50
|
33
|
|
|
10
|
if ($next_token && $next_token->{type} == BUILTIN_FUNC && $next_token->{data} eq 'sort') { |
|
|
|
33
|
|
|
|
|
66
|
|
|
|
|
|
|
push @violations, { |
67
|
|
|
|
|
|
|
filename => $file, |
68
|
|
|
|
|
|
|
line => $token->{line}, |
69
|
0
|
|
|
|
|
0
|
description => DESC, |
70
|
|
|
|
|
|
|
explanation => EXPL, |
71
|
|
|
|
|
|
|
policy => __PACKAGE__, |
72
|
|
|
|
|
|
|
}; |
73
|
0
|
|
|
|
|
0
|
next; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
5
|
|
|
|
|
16
|
return \@violations; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
|