Perl/Lint/Policy/RegularExpressions/RequireDotMatchAnything.pm

filter: Statementstmt 64.8% 48 / 74 Branchbran 41.6% 15 / 36 Conditioncond 21.8% 14 / 64 MC/DCmcdc 3.3% 1 / 30 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 39.8% 84 / 211 CC 41 SCAR 59.5
CC
41
Cov
44%
evaluate
430.0
BEGIN
1.0
BEGIN
1.0
CRAP 383.3
« Perl/Lint/Policy/ValuesAndExpressions/ProhibitMixedBooleanOperators.pm ↑ Summary Perl/Lint/Policy/RegularExpressions/RequireLineBoundaryMatching.pm »
1 package Perl::Lint::Policy::RegularExpressions::RequireDotMatchAnything;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 DESC => 'Regular expression without "/s" flag',
9 EXPL => [240, 241],
10 3 };
11  
12 2 ▶sub evaluate {
Subroutine evaluate: called CC=41 SCAR=60.6
Pod undocumented
13 2 my ($class, $file, $tokens, $src, $args) = @_;
14  
15 2 my @violations;
16  
17 2 my $depth = 0;
18 2 my $is_non_target_reg = 0;
19  
20 2 my $enabled_re_m_depth = -1; # use negative value as default
21 2 my @enabled_re_m_depths;
22  
23 2 my $disable_re_m_depth = -1; # use negative value as default
24 2 my @disable_re_m_depths;
25  
26 2 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 51 2 53
27 51 my $token_type = $token->{type};
28 51 my $token_data = $token->{data};
29  
30 51 my $next_token = $tokens->[$i+1];
31 51 my $next_token_type = $next_token->{type};
32 51 my $next_token_data = $next_token->{data};
33  
34 51 ▶ if (!$is_non_target_reg && $token_type == REG_DELIM) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $is_non_target_reg and $token_type == 151) 0 51 51
Condition66%2/3
not $is_non_target_reg and $token_type == 151
!ll&&!rl&&r
8430
MC/DC0%0/2
not $is_non_target_reg and $token_type == 151
not $is_non_target_reg $token_type == 151
Truth table66%2/3
not(A) and B
A= not $is_non_target_regB= $token_type == 151
ABresult
0X0
100
111
35 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $next_token_type and $next_token_type == 106 || $next_token_type == 144 && !($next_token_data =~ /s/)) 0 0 0
Condition0%0/9
defined $next_token_type and $next_token_type == 106 || $next_token_type == 144 && !($next_token_data =~ /s/)
!ll&&!rl&&r
000
$next_token_type == 106 or $next_token_type == 144 and not $next_token_data =~ /s/
l!l&&r!l&&!r
000
$next_token_type == 144 and not $next_token_data =~ /s/
!ll&&!rl&&r
000
MC/DC0%0/4
defined $next_token_type and $next_token_type == 106 || $next_token_type == 144 && !($next_token_data =~ /s/)
defined $next_token_type $next_token_type == 106 $next_token_type == 144 not $next_token_data =~ /s/
Truth table0%0/5
A and B or C and not(D)
A= defined $next_token_typeB= $next_token_type == 106C= $next_token_type == 144D= not $next_token_data =~ /s/
ABCDresult
0XXX0
100X0
10100
11XX1
10111
36 defined $next_token_type &&
37 (
38 $next_token_type == SEMI_COLON || # when any regex options don't exist
39 ($next_token_type == REG_OPT && $next_token_data !~ /s/) # when the `m` regex option doesn't exist
40 )
41 ) {
42 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not $enabled_re_m_depth >= 0 && $depth >= $enabled_re_m_depth or $disable_re_m_depth >= 0 and $disable_re_m_depth > $enabled_re_m_depth) 0 0 0
Condition0%0/9
not $enabled_re_m_depth >= 0 && $depth >= $enabled_re_m_depth or $disable_re_m_depth >= 0 and $disable_re_m_depth > $enabled_re_m_depth
l!l&&r!l&&!r
000
$enabled_re_m_depth >= 0 && $depth >= $enabled_re_m_depth
!ll&&!rl&&r
000
$disable_re_m_depth >= 0 and $disable_re_m_depth > $enabled_re_m_depth
!ll&&!rl&&r
000
MC/DC0%0/4
not $enabled_re_m_depth >= 0 && $depth >= $enabled_re_m_depth or $disable_re_m_depth >= 0 and $disable_re_m_depth > $enabled_re_m_depth
$enabled_re_m_depth >= 0 $depth >= $enabled_re_m_depth $disable_re_m_depth >= 0 $disable_re_m_depth > $enabled_re_m_depth
Truth table0%0/5
not(A && B) or C and D
A= $enabled_re_m_depth >= 0B= $depth >= $enabled_re_m_depthC= $disable_re_m_depth >= 0D= $disable_re_m_depth > $enabled_re_m_depth
ABCDresult
0XXX1
10XX1
11111
110X0
11100
43 !($enabled_re_m_depth >= 0 && $depth >= $enabled_re_m_depth) ||
44 ($disable_re_m_depth >= 0 && $disable_re_m_depth > $enabled_re_m_depth)
45 ) {
46 push @violations, {
47 filename => $file,
48 line => $token->{line},
49 0 description => DESC,
50 explanation => EXPL,
51 policy => __PACKAGE__,
52 };
53 }
54 }
55  
56 0 next;
57 }
58  
59 # Ignore regexes which are unnecessary to check
60 # XXX more?
61 51 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 154 or $token_type == 147 or $token_type == 145 or $token_type == 148) 2 49 51
Condition66%6/9
$token_type == 154 or $token_type == 147 or $token_type == 145 or $token_type == 148
l!l&&r!l&&!r
2049
$token_type == 154 or $token_type == 147 or $token_type == 145
l!l&&r!l&&!r
2049
$token_type == 154 or $token_type == 147
l!l&&r!l&&!r
0249
MC/DC25%1/4
$token_type == 154 or $token_type == 147 or $token_type == 145 or $token_type == 148
$token_type == 154 $token_type == 147 $token_type == 145 $token_type == 148
Truth table40%2/5
A or B or C or D
A= $token_type == 154B= $token_type == 147C= $token_type == 145D= $token_type == 148
ABCDresult
1XXX1
01XX1
001X1
00011
00000
62 $token_type == REG_ALL_REPLACE ||
63 $token_type == REG_LIST ||
64 $token_type == REG_QUOTE ||
65 $token_type == REG_EXEC
66 ) {
67 2 $is_non_target_reg = 1;
68 2 next;
69 }
70  
71 49 ▶ if ($token_type == SEMI_COLON) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 106) 11 38 49
72 11 $is_non_target_reg = 0;
73 11 next;
74 }
75  
76 # Represent block scope hierarchy
77 38 ▶ if ($token_type == LEFT_BRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 109) 1 37 38
78 1 $depth++;
79 1 next;
80 }
81 37 ▶ if ($token_type == RIGHT_BRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 110) 1 36 37
82 1 ▶ if ($enabled_re_m_depth == $depth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enabled_re_m_depth == $depth) 0 1 1
83 0 pop @enabled_re_m_depths;
84 0 ▶ $enabled_re_m_depth = $enabled_re_m_depths[-1] // -1;
Condition0%0/2
$enabled_re_m_depths[-1] // -1
l!l
00
MC/DC0%0/1
$enabled_re_m_depths[-1] // -1
$enabled_re_m_depths[-1]
Truth table0%0/2
A
A= $enabled_re_m_depths[-1]
Aresult
11
00
85 }
86 1 ▶ if ($disable_re_m_depth == $depth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($disable_re_m_depth == $depth) 0 1 1
87 0 pop @disable_re_m_depths;
88 0 ▶ $disable_re_m_depth = $disable_re_m_depths[-1] // -1;
Condition0%0/2
$disable_re_m_depths[-1] // -1
l!l
00
MC/DC0%0/1
$disable_re_m_depths[-1] // -1
$disable_re_m_depths[-1]
Truth table0%0/2
A
A= $disable_re_m_depths[-1]
Aresult
11
00
89 }
90 1 $depth--;
91 1 next;
92 }
93  
94 # for
95 # `use re qw{/s}`
96 # `use re '/s'`
97 36 ▶ if ($token_type == USED_NAME && $token_data eq 're') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 94 and $token_data eq "re") 0 36 36
Condition66%2/3
$token_type == 94 and $token_data eq "re"
!ll&&!rl&&r
2880
MC/DC0%0/2
$token_type == 94 and $token_data eq "re"
$token_type == 94 $token_data eq "re"
Truth table66%2/3
A and B
A= $token_type == 94B= $token_data eq "re"
ABresult
0X0
100
111
98 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
99 0 $token_type = $token->{type};
100 0 $token_data = $token->{data};
101 0 ▶ if ($token_type == SEMI_COLON) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 106) 0 0 0
102 0 last;
103 }
104 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 173 || $token_type == 172 || $token_type == 187 and $token_data =~ /s/) 0 0 0
Condition0%0/9
$token_type == 173 || $token_type == 172 || $token_type == 187 and $token_data =~ /s/
!ll&&!rl&&r
000
$token_type == 173 or $token_type == 172 or $token_type == 187
l!l&&r!l&&!r
000
$token_type == 173 or $token_type == 172
l!l&&r!l&&!r
000
MC/DC0%0/4
$token_type == 173 || $token_type == 172 || $token_type == 187 and $token_data =~ /s/
$token_type == 173 $token_type == 172 $token_type == 187 $token_data =~ /s/
Truth table0%0/7
A or B or C and D
A= $token_type == 173B= $token_type == 172C= $token_type == 187D= $token_data =~ /s/
ABCDresult
000X0
1XX00
01X00
00100
1XX11
01X11
00111
105 ($token_type == RAW_STRING || $token_type == STRING || $token_type == REG_EXP) &&
106 $token_data =~ /s/
107 ) {
108 0 push @enabled_re_m_depths, $depth;
109 0 $enabled_re_m_depth = $depth;
110 }
111 }
112  
113 0 next;
114 }
115  
116 # for
117 # `no re qw{/s}`
118 # `no re '/s'`
119 36 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 70 and $token_data eq "no" and $next_token_type == 122 and $next_token_data eq "re") 0 36 36
Condition44%4/9
$token_type == 70 and $token_data eq "no" and $next_token_type == 122 and $next_token_data eq "re"
!ll&&!rl&&r
3600
$token_type == 70 and $token_data eq "no" and $next_token_type == 122
!ll&&!rl&&r
3600
$token_type == 70 and $token_data eq "no"
!ll&&!rl&&r
3510
MC/DC0%0/4
$token_type == 70 and $token_data eq "no" and $next_token_type == 122 and $next_token_data eq "re"
$token_type == 70 $token_data eq "no" $next_token_type == 122 $next_token_data eq "re"
Truth table40%2/5
A and B and C and D
A= $token_type == 70B= $token_data eq "no"C= $next_token_type == 122D= $next_token_data eq "re"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
120 $token_type == BUILTIN_FUNC &&
121 $token_data eq 'no' &&
122 $next_token_type == KEY &&
123 $next_token_data eq 're'
124 ) {
125 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
126 0 $token_type = $token->{type};
127 0 $token_data = $token->{data};
128 0 ▶ if ($token_type == SEMI_COLON) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 106) 0 0 0
129 0 last;
130 }
131 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 173 || $token_type == 172 || $token_type == 187 and $token_data =~ /s/) 0 0 0
Condition0%0/9
$token_type == 173 || $token_type == 172 || $token_type == 187 and $token_data =~ /s/
!ll&&!rl&&r
000
$token_type == 173 or $token_type == 172 or $token_type == 187
l!l&&r!l&&!r
000
$token_type == 173 or $token_type == 172
l!l&&r!l&&!r
000
MC/DC0%0/4
$token_type == 173 || $token_type == 172 || $token_type == 187 and $token_data =~ /s/
$token_type == 173 $token_type == 172 $token_type == 187 $token_data =~ /s/
Truth table0%0/7
A or B or C and D
A= $token_type == 173B= $token_type == 172C= $token_type == 187D= $token_data =~ /s/
ABCDresult
000X0
1XX00
01X00
00100
1XX11
01X11
00111
132 ($token_type == RAW_STRING || $token_type == STRING || $token_type == REG_EXP) &&
133 $token_data =~ /s/
134 ) {
135 0 push @disable_re_m_depths, $depth;
136 0 $disable_re_m_depth = $depth;
137 }
138 }
139  
140 0 next;
141 }
142 }
143  
144 2 return \@violations;
145 }
146  
147 3 1;
148  
« Perl/Lint/Policy/ValuesAndExpressions/ProhibitMixedBooleanOperators.pm ↑ Summary Perl/Lint/Policy/RegularExpressions/RequireLineBoundaryMatching.pm »