| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::BuiltinFunctions::ProhibitVoidGrep; |
|
2
|
133
|
|
|
133
|
|
68877
|
use strict; |
|
|
133
|
|
|
|
|
187
|
|
|
|
133
|
|
|
|
|
3071
|
|
|
3
|
133
|
|
|
133
|
|
430
|
use warnings; |
|
|
133
|
|
|
|
|
165
|
|
|
|
133
|
|
|
|
|
2489
|
|
|
4
|
133
|
|
|
133
|
|
804
|
use Perl::Lint::Constants::Type; |
|
|
133
|
|
|
|
|
165
|
|
|
|
133
|
|
|
|
|
57981
|
|
|
5
|
133
|
|
|
133
|
|
584
|
use parent "Perl::Lint::Policy"; |
|
|
133
|
|
|
|
|
168
|
|
|
|
133
|
|
|
|
|
571
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# TODO REFACTOR!!! |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use constant { |
|
10
|
133
|
|
|
|
|
34082
|
DESC => '"grep" used in void context', |
|
11
|
|
|
|
|
|
|
EXPL => 'Use a "for" loop instead', |
|
12
|
133
|
|
|
133
|
|
6383
|
}; |
|
|
133
|
|
|
|
|
175
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub evaluate { |
|
15
|
6
|
|
|
6
|
0
|
9
|
my ($class, $file, $tokens, $args) = @_; |
|
16
|
|
|
|
|
|
|
|
|
17
|
6
|
|
|
|
|
5
|
my @violations; |
|
18
|
6
|
|
|
|
|
6
|
my $is_in_context = 0; |
|
19
|
6
|
|
|
|
|
5
|
my $is_in_grep = 0; |
|
20
|
6
|
|
|
|
|
3
|
my $is_in_ctrl_statement = 0; |
|
21
|
6
|
|
|
|
|
7
|
my $left_brace_num = 0; |
|
22
|
6
|
|
|
|
|
17
|
for (my $i = 0; my $token = $tokens->[$i]; $i++) { |
|
23
|
378
|
|
|
|
|
255
|
my $token_type = $token->{type}; |
|
24
|
378
|
|
|
|
|
233
|
my $token_data = $token->{data}; |
|
25
|
378
|
100
|
100
|
|
|
2105
|
if ($token_type == BUILTIN_FUNC) { |
|
|
|
100
|
100
|
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
26
|
50
|
100
|
|
|
|
60
|
if ($token_data eq 'grep') { |
|
27
|
42
|
100
|
|
|
|
58
|
next if $is_in_grep; |
|
28
|
|
|
|
|
|
|
|
|
29
|
24
|
100
|
|
|
|
35
|
if ($is_in_ctrl_statement) { |
|
|
|
100
|
|
|
|
|
|
|
30
|
5
|
100
|
|
|
|
11
|
if ($left_brace_num) { |
|
31
|
|
|
|
|
|
|
push @violations, { |
|
32
|
|
|
|
|
|
|
filename => $file, |
|
33
|
|
|
|
|
|
|
line => $token->{line}, |
|
34
|
3
|
|
|
|
|
8
|
description => DESC, |
|
35
|
|
|
|
|
|
|
explanation => EXPL, |
|
36
|
|
|
|
|
|
|
policy => __PACKAGE__, |
|
37
|
|
|
|
|
|
|
}; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
elsif (!$is_in_context) { |
|
41
|
|
|
|
|
|
|
push @violations, { |
|
42
|
|
|
|
|
|
|
filename => $file, |
|
43
|
|
|
|
|
|
|
line => $token->{line}, |
|
44
|
11
|
|
|
|
|
28
|
description => DESC, |
|
45
|
|
|
|
|
|
|
explanation => EXPL, |
|
46
|
|
|
|
|
|
|
policy => __PACKAGE__, |
|
47
|
|
|
|
|
|
|
}; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
24
|
|
|
|
|
19
|
$is_in_grep = 1; |
|
51
|
24
|
|
|
|
|
36
|
next; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
8
|
|
|
|
|
11
|
$is_in_context = 1; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
elsif ($token_type == ASSIGN) { |
|
56
|
3
|
|
|
|
|
5
|
$is_in_context = 1; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
elsif ( # NOTE enough? |
|
59
|
|
|
|
|
|
|
$token_type == IF_STATEMENT || |
|
60
|
|
|
|
|
|
|
$token_type == FOR_STATEMENT || |
|
61
|
|
|
|
|
|
|
$token_type == WHILE_STATEMENT || |
|
62
|
|
|
|
|
|
|
$token_type == UNLESS_STATEMENT |
|
63
|
|
|
|
|
|
|
) { |
|
64
|
5
|
|
|
|
|
6
|
$is_in_ctrl_statement = 1; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
elsif ($is_in_ctrl_statement) { |
|
67
|
50
|
100
|
|
|
|
107
|
if ($token_type == LEFT_BRACE) { |
|
|
|
100
|
|
|
|
|
|
|
68
|
8
|
|
|
|
|
12
|
$left_brace_num++; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_BRACE) { |
|
71
|
8
|
|
|
|
|
5
|
$left_brace_num--; |
|
72
|
8
|
100
|
|
|
|
14
|
if ($left_brace_num <= 0) { |
|
73
|
5
|
|
|
|
|
5
|
$is_in_ctrl_statement = 0; |
|
74
|
5
|
|
|
|
|
8
|
$is_in_grep = 0; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
elsif ($token_type == SEMI_COLON) { |
|
79
|
20
|
|
|
|
|
13
|
$is_in_context = 0; |
|
80
|
20
|
|
|
|
|
30
|
$is_in_grep = 0; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
6
|
|
|
|
|
21
|
return \@violations; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
|
88
|
|
|
|
|
|
|
|