| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::ValuesAndExpressions::ProhibitInterpolationOfLiterals; |
|
2
|
134
|
|
|
134
|
|
68805
|
use strict; |
|
|
134
|
|
|
|
|
179
|
|
|
|
134
|
|
|
|
|
3102
|
|
|
3
|
134
|
|
|
134
|
|
402
|
use warnings; |
|
|
134
|
|
|
|
|
166
|
|
|
|
134
|
|
|
|
|
2859
|
|
|
4
|
134
|
|
|
134
|
|
427
|
use List::Util qw/any/; |
|
|
134
|
|
|
|
|
169
|
|
|
|
134
|
|
|
|
|
6772
|
|
|
5
|
134
|
|
|
134
|
|
853
|
use Perl::Lint::Constants::Type; |
|
|
134
|
|
|
|
|
176
|
|
|
|
134
|
|
|
|
|
58373
|
|
|
6
|
134
|
|
|
134
|
|
573
|
use parent "Perl::Lint::Policy"; |
|
|
134
|
|
|
|
|
174
|
|
|
|
134
|
|
|
|
|
562
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use constant { |
|
9
|
134
|
|
|
|
|
48800
|
DESC => 'Useless interpolation of literal string', |
|
10
|
|
|
|
|
|
|
EXPL => [51], |
|
11
|
134
|
|
|
134
|
|
6237
|
}; |
|
|
134
|
|
|
|
|
170
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# TODO integrate duplicated functions |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub evaluate { |
|
16
|
17
|
|
|
17
|
0
|
32
|
my ($class, $file, $tokens, $src, $args) = @_; |
|
17
|
|
|
|
|
|
|
|
|
18
|
17
|
|
|
|
|
24
|
my @allow_double_quote_literals; |
|
19
|
|
|
|
|
|
|
my $allow_if_string_contains_single_quote; |
|
20
|
17
|
100
|
|
|
|
52
|
if (my $this_policies_arg = $args->{prohibit_interpolation_of_literals}) { |
|
21
|
6
|
|
|
|
|
12
|
$allow_if_string_contains_single_quote = $this_policies_arg->{allow_if_string_contains_single_quote}; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# e.g. {allow => 'qq( qq{ qq[ qq/'}} |
|
24
|
6
|
|
|
|
|
10
|
my $allow_double_quote_literals = $this_policies_arg->{allow}; |
|
25
|
6
|
|
100
|
|
|
45
|
for my $allowed_literal (split /\s+/, $allow_double_quote_literals || '') { |
|
26
|
10
|
|
|
|
|
20
|
$allowed_literal =~ s/\Aqq//; |
|
27
|
10
|
|
|
|
|
21
|
push @allow_double_quote_literals, substr $allowed_literal, 0, 1; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
17
|
|
|
|
|
20
|
my @violations; |
|
33
|
17
|
|
|
|
|
58
|
for (my $i = 0, my $token_type, my $token_data; my $token = $tokens->[$i]; $i++) { |
|
34
|
355
|
|
|
|
|
262
|
$token_type = $token->{type}; |
|
35
|
355
|
|
|
|
|
285
|
$token_data = $token->{data}; |
|
36
|
|
|
|
|
|
|
|
|
37
|
355
|
100
|
|
|
|
759
|
if ($token_type == STRING) { |
|
|
|
100
|
|
|
|
|
|
|
38
|
23
|
100
|
|
|
|
26
|
if ($allow_if_string_contains_single_quote) { |
|
39
|
2
|
50
|
|
|
|
8
|
if ($token_data =~ /'/) { |
|
40
|
2
|
|
|
|
|
5
|
next; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# XXX NP? :( |
|
45
|
21
|
100
|
|
|
|
71
|
if ($token_data =~ /(\\*)(?:[\$\@]|\\\w)/) { |
|
46
|
16
|
100
|
|
|
|
41
|
if (length($1) % 2 == 0) { # check escaped or not |
|
47
|
8
|
|
|
|
|
15
|
next; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
push @violations, { |
|
52
|
|
|
|
|
|
|
filename => $file, |
|
53
|
|
|
|
|
|
|
line => $token->{line}, |
|
54
|
13
|
|
|
|
|
58
|
description => DESC, |
|
55
|
|
|
|
|
|
|
explanation => EXPL, |
|
56
|
|
|
|
|
|
|
policy => __PACKAGE__, |
|
57
|
|
|
|
|
|
|
}; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
elsif ($token_type == REG_DOUBLE_QUOTE) { |
|
60
|
40
|
|
|
|
|
56
|
$token = $tokens->[++$i]; |
|
61
|
40
|
|
|
|
|
36
|
$token_data = $token->{data}; |
|
62
|
|
|
|
|
|
|
|
|
63
|
40
|
100
|
|
31
|
|
172
|
if (any {$_ eq $token_data} @allow_double_quote_literals) { |
|
|
31
|
|
|
|
|
45
|
|
|
64
|
10
|
|
|
|
|
28
|
next; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
30
|
|
|
|
|
54
|
$token = $tokens->[++$i]; |
|
68
|
30
|
|
|
|
|
36
|
$token_data = $token->{data}; |
|
69
|
30
|
100
|
|
|
|
49
|
if ($allow_if_string_contains_single_quote) { |
|
70
|
2
|
50
|
|
|
|
7
|
if ($token_data =~ /'/) { |
|
71
|
2
|
|
|
|
|
4
|
next; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# XXX NP? :( |
|
76
|
28
|
100
|
|
|
|
112
|
if ($token_data =~ /(\\*)(?:[\$\@]\S+|\\\w)/) { |
|
77
|
16
|
100
|
|
|
|
29
|
if (length($1) % 2 == 0) { # check escaped or not |
|
78
|
8
|
|
|
|
|
15
|
next; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
push @violations, { |
|
83
|
|
|
|
|
|
|
filename => $file, |
|
84
|
|
|
|
|
|
|
line => $token->{line}, |
|
85
|
20
|
|
|
|
|
93
|
description => DESC, |
|
86
|
|
|
|
|
|
|
explanation => EXPL, |
|
87
|
|
|
|
|
|
|
policy => __PACKAGE__, |
|
88
|
|
|
|
|
|
|
}; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
17
|
|
|
|
|
67
|
return \@violations; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
|
96
|
|
|
|
|
|
|
|