line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::RegularExpressions::RequireBracesForMultiline; |
2
|
134
|
|
|
134
|
|
81099
|
use strict; |
|
134
|
|
|
|
|
177
|
|
|
134
|
|
|
|
|
3457
|
|
3
|
134
|
|
|
134
|
|
440
|
use warnings; |
|
134
|
|
|
|
|
158
|
|
|
134
|
|
|
|
|
2919
|
|
4
|
134
|
|
|
134
|
|
787
|
use Perl::Lint::Constants::Type; |
|
134
|
|
|
|
|
156
|
|
|
134
|
|
|
|
|
62666
|
|
5
|
134
|
|
|
134
|
|
594
|
use parent "Perl::Lint::Policy"; |
|
134
|
|
|
|
|
183
|
|
|
134
|
|
|
|
|
606
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
8
|
134
|
|
|
|
|
34003
|
DESC => 'Use "{" and "}" to delimit multi-line regexps', |
9
|
|
|
|
|
|
|
EXPL => [242], |
10
|
134
|
|
|
134
|
|
7115
|
}; |
|
134
|
|
|
|
|
178
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub evaluate { |
13
|
7
|
|
|
7
|
0
|
14
|
my ($class, $file, $tokens, $src, $args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
7
|
|
|
|
|
24
|
my $brackets_regex = qr/\A\{\Z/; |
16
|
7
|
100
|
|
|
|
24
|
if ($args->{require_braces_for_multiline}->{allow_all_brackets}) { |
17
|
1
|
|
|
|
|
3
|
$brackets_regex = qr/\A[\{\(\[\<]\Z/; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
7
|
|
|
|
|
12
|
my @violations; |
21
|
7
|
|
|
|
|
31
|
for (my $i = 0, my $token_type; my $token = $tokens->[$i]; $i++) { |
22
|
210
|
|
|
|
|
140
|
$token_type = $token->{type}; |
23
|
|
|
|
|
|
|
|
24
|
210
|
100
|
100
|
|
|
580
|
if ($token_type == REG_EXP || $token_type == REG_REPLACE_FROM) { |
25
|
30
|
100
|
|
|
|
121
|
if (my @backslashes = $token->{data} =~ /(\\*)\n/g) { |
26
|
24
|
|
|
|
|
26
|
my $reg_delim_token = $tokens->[$i-1]; |
27
|
24
|
100
|
|
|
|
87
|
if ($reg_delim_token->{data} !~ $brackets_regex) { |
28
|
8
|
|
|
|
|
10
|
for my $backslash (@backslashes) { |
29
|
8
|
50
|
33
|
|
|
14
|
if (!$backslash || length($backslash) % 2 == 0) { |
30
|
|
|
|
|
|
|
push @violations, { |
31
|
|
|
|
|
|
|
filename => $file, |
32
|
|
|
|
|
|
|
line => $token->{line}, |
33
|
8
|
|
|
|
|
24
|
description => DESC, |
34
|
|
|
|
|
|
|
explanation => EXPL, |
35
|
|
|
|
|
|
|
policy => __PACKAGE__, |
36
|
|
|
|
|
|
|
}; |
37
|
8
|
|
|
|
|
21
|
last; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
7
|
|
|
|
|
30
|
return \@violations; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
|