| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::CodeLayout::ProhibitQuotedWordLists; |
|
2
|
134
|
|
|
134
|
|
96966
|
use strict; |
|
|
134
|
|
|
|
|
254
|
|
|
|
134
|
|
|
|
|
4964
|
|
|
3
|
134
|
|
|
134
|
|
618
|
use warnings; |
|
|
134
|
|
|
|
|
284
|
|
|
|
134
|
|
|
|
|
3454
|
|
|
4
|
134
|
|
|
134
|
|
988
|
use Perl::Lint::Constants::Type; |
|
|
134
|
|
|
|
|
339
|
|
|
|
134
|
|
|
|
|
84827
|
|
|
5
|
134
|
|
|
134
|
|
814
|
use parent "Perl::Lint::Policy"; |
|
|
134
|
|
|
|
|
296
|
|
|
|
134
|
|
|
|
|
859
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# TODO TODO TODO integrate duplicated functions between assign context and use context !!!! |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use constant { |
|
10
|
134
|
|
|
|
|
82333
|
DESC => 'List of quoted literal words', |
|
11
|
|
|
|
|
|
|
EXPL => 'Use "qw()" instead', |
|
12
|
134
|
|
|
134
|
|
9174
|
}; |
|
|
134
|
|
|
|
|
232
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub evaluate { |
|
15
|
11
|
|
|
11
|
0
|
33
|
my ($class, $file, $tokens, $src, $args) = @_; |
|
16
|
|
|
|
|
|
|
|
|
17
|
11
|
|
100
|
|
|
75
|
my $min_elements = $args->{prohibit_quoted_word_lists}->{min_elements} || 2; |
|
18
|
11
|
|
100
|
|
|
64
|
my $strict = $args->{prohibit_quoted_word_lists}->{strict} || 0; |
|
19
|
|
|
|
|
|
|
|
|
20
|
11
|
|
|
|
|
16
|
my @violations; |
|
21
|
11
|
|
|
|
|
57
|
for (my $i = 0; my $token = $tokens->[$i]; $i++) { |
|
22
|
151
|
|
|
|
|
121
|
my $token_type = $token->{type}; |
|
23
|
|
|
|
|
|
|
|
|
24
|
151
|
100
|
66
|
|
|
750
|
if ( |
|
|
|
100
|
100
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$token_type == ARRAY_VAR || |
|
26
|
|
|
|
|
|
|
$token_type == LOCAL_ARRAY_VAR || |
|
27
|
|
|
|
|
|
|
$token_type == GLOBAL_ARRAY_VAR |
|
28
|
|
|
|
|
|
|
) { |
|
29
|
22
|
|
|
|
|
24
|
$token = $tokens->[++$i]; |
|
30
|
22
|
|
|
|
|
22
|
$token_type = $token->{type}; |
|
31
|
22
|
50
|
|
|
|
69
|
if ($token_type == ASSIGN) { |
|
32
|
22
|
|
|
|
|
22
|
$token = $tokens->[++$i]; |
|
33
|
22
|
|
|
|
|
26
|
$token_type = $token->{type}; |
|
34
|
22
|
50
|
|
|
|
44
|
if ($token_type == LEFT_PAREN) { |
|
35
|
22
|
|
|
|
|
27
|
my $left_paren_num = 1; |
|
36
|
22
|
|
|
|
|
17
|
my $is_violated = 1; |
|
37
|
22
|
|
|
|
|
24
|
my $elem_num = 0; |
|
38
|
|
|
|
|
|
|
|
|
39
|
22
|
|
|
|
|
48
|
for ($i++; $token = $tokens->[$i]; $i++) { |
|
40
|
131
|
|
|
|
|
110
|
$token_type = $token->{type}; |
|
41
|
131
|
50
|
66
|
|
|
461
|
if ($token_type == LEFT_PAREN) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
0
|
$left_paren_num++; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_PAREN) { |
|
45
|
22
|
50
|
|
|
|
44
|
if (--$left_paren_num <= 0) { |
|
46
|
22
|
100
|
100
|
|
|
66
|
if ($is_violated && $elem_num >= $min_elements) { |
|
47
|
10
|
|
|
|
|
40
|
push @violations, { |
|
48
|
|
|
|
|
|
|
filename => $file, |
|
49
|
|
|
|
|
|
|
line => $token->{line}, |
|
50
|
|
|
|
|
|
|
description => DESC, |
|
51
|
|
|
|
|
|
|
explanation => EXPL, |
|
52
|
|
|
|
|
|
|
policy => __PACKAGE__ |
|
53
|
|
|
|
|
|
|
}; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
22
|
|
|
|
|
54
|
last; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
elsif ($token_type == STRING || $token_type == RAW_STRING) { |
|
59
|
57
|
|
|
|
|
39
|
$elem_num++; |
|
60
|
|
|
|
|
|
|
|
|
61
|
57
|
100
|
|
|
|
81
|
next if $strict; |
|
62
|
|
|
|
|
|
|
|
|
63
|
51
|
100
|
|
|
|
167
|
if ($token->{data} !~ /\A[a-zA-Z-]+\Z/) { |
|
64
|
7
|
|
|
|
|
15
|
$is_violated = 0; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
elsif ($token_type != COMMA) { |
|
68
|
13
|
|
|
|
|
9
|
$elem_num++; |
|
69
|
13
|
|
|
|
|
21
|
$is_violated = 0; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
elsif ($token_type == USE_DECL) { |
|
76
|
13
|
|
|
|
|
36
|
USE_STATEMENT: for ($i++; $token = $tokens->[$i]; $i++) { |
|
77
|
34
|
|
|
|
|
33
|
$token_type = $token->{type}; |
|
78
|
|
|
|
|
|
|
|
|
79
|
34
|
100
|
|
|
|
80
|
if ($token_type == LEFT_PAREN) { |
|
|
|
100
|
|
|
|
|
|
|
80
|
5
|
|
|
|
|
7
|
my $left_paren_num = 1; |
|
81
|
5
|
|
|
|
|
8
|
my $is_violated = 1; |
|
82
|
5
|
|
|
|
|
5
|
my $elem_num = 0; |
|
83
|
|
|
|
|
|
|
|
|
84
|
5
|
|
|
|
|
14
|
for ($i++; $token = $tokens->[$i]; $i++) { |
|
85
|
29
|
|
|
|
|
21
|
$token_type = $token->{type}; |
|
86
|
29
|
50
|
66
|
|
|
110
|
if ($token_type == LEFT_PAREN) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
0
|
$left_paren_num++; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_PAREN) { |
|
90
|
5
|
50
|
|
|
|
11
|
if (--$left_paren_num <= 0) { |
|
91
|
5
|
100
|
100
|
|
|
18
|
if ($is_violated && $elem_num >= $min_elements) { |
|
92
|
2
|
|
|
|
|
14
|
push @violations, { |
|
93
|
|
|
|
|
|
|
filename => $file, |
|
94
|
|
|
|
|
|
|
line => $token->{line}, |
|
95
|
|
|
|
|
|
|
description => DESC, |
|
96
|
|
|
|
|
|
|
explanation => EXPL, |
|
97
|
|
|
|
|
|
|
policy => __PACKAGE__, |
|
98
|
|
|
|
|
|
|
}; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
5
|
|
|
|
|
18
|
last USE_STATEMENT; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
elsif ($token_type == STRING || $token_type == RAW_STRING) { |
|
104
|
13
|
|
|
|
|
13
|
$elem_num++; |
|
105
|
|
|
|
|
|
|
|
|
106
|
13
|
100
|
|
|
|
21
|
next if $strict; |
|
107
|
|
|
|
|
|
|
|
|
108
|
10
|
100
|
|
|
|
37
|
if ($token->{data} !~ /\A[a-zA-Z-]+\Z/) { |
|
109
|
1
|
|
|
|
|
2
|
$is_violated = 0; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
elsif ($token_type != COMMA) { |
|
113
|
3
|
|
|
|
|
4
|
$elem_num++; |
|
114
|
3
|
|
|
|
|
6
|
$is_violated = 0; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
elsif ($token_type == SEMI_COLON) { |
|
119
|
8
|
|
|
|
|
18
|
last; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
|
|
125
|
11
|
|
|
|
|
52
|
return \@violations; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |
|
129
|
|
|
|
|
|
|
|