Perl/Lint/Policy/RegularExpressions/RequireExtendedFormatting.pm

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