line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::RegularExpressions::ProhibitSingleCharAlternation; |
2
|
134
|
|
|
134
|
|
94482
|
use strict; |
|
134
|
|
|
|
|
268
|
|
|
134
|
|
|
|
|
4946
|
|
3
|
134
|
|
|
134
|
|
713
|
use warnings; |
|
134
|
|
|
|
|
215
|
|
|
134
|
|
|
|
|
3623
|
|
4
|
134
|
|
|
134
|
|
1043
|
use Perl::Lint::Constants::Type; |
|
134
|
|
|
|
|
234
|
|
|
134
|
|
|
|
|
84441
|
|
5
|
134
|
|
|
134
|
|
833
|
use parent "Perl::Lint::Policy"; |
|
134
|
|
|
|
|
248
|
|
|
134
|
|
|
|
|
925
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
8
|
134
|
|
|
|
|
51775
|
DESC => 'Use [%s] instead of %s', |
9
|
|
|
|
|
|
|
EXPL => [265], |
10
|
134
|
|
|
134
|
|
10069
|
}; |
|
134
|
|
|
|
|
261
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub evaluate { |
13
|
8
|
|
|
8
|
0
|
17
|
my ($class, $file, $tokens, $src, $args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
8
|
|
|
|
|
8
|
my @violations; |
16
|
8
|
|
|
|
|
32
|
for (my $i = 0, my $token_type, my $token_data; my $token = $tokens->[$i]; $i++) { |
17
|
159
|
|
|
|
|
126
|
$token_type = $token->{type}; |
18
|
159
|
|
|
|
|
154
|
$token_data = $token->{data}; |
19
|
|
|
|
|
|
|
|
20
|
159
|
100
|
|
|
|
320
|
if ($token_type == REG_EXP) { |
21
|
18
|
100
|
|
|
|
116
|
if (my @groups = $token_data =~ /\( \?\: \s* (.+?) \s* \)/gx) { |
22
|
15
|
|
|
|
|
15
|
TRAVERSE_REGEX: for my $group (@groups) { |
23
|
15
|
100
|
|
|
|
28
|
if ($group =~ /\A \w \Z/x) { |
24
|
1
|
|
|
|
|
3
|
last; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
14
|
|
|
|
|
13
|
my @singles; |
28
|
14
|
|
|
|
|
70
|
for my $part (split /\s* \| \s*/x, $group) { |
29
|
68
|
100
|
|
|
|
124
|
if ($part !~ /\A \w+ \Z/x) { |
30
|
5
|
|
|
|
|
18
|
last TRAVERSE_REGEX; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
63
|
100
|
|
|
|
93
|
if (length $part == 1) { # if single char |
34
|
33
|
|
|
|
|
38
|
push @singles, $part; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
9
|
100
|
|
|
|
22
|
if (scalar @singles > 1) { |
39
|
8
|
|
|
|
|
65
|
push @violations, { |
40
|
|
|
|
|
|
|
filename => $file, |
41
|
|
|
|
|
|
|
line => $token->{line}, |
42
|
|
|
|
|
|
|
description => sprintf( |
43
|
|
|
|
|
|
|
DESC, |
44
|
|
|
|
|
|
|
join('', @singles), |
45
|
|
|
|
|
|
|
join('|', @singles), |
46
|
|
|
|
|
|
|
), |
47
|
|
|
|
|
|
|
explanation => EXPL, |
48
|
|
|
|
|
|
|
policy => __PACKAGE__, |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
8
|
|
|
|
|
32
|
return \@violations; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|