Review/Filter.pm

filter: Statementstmt 89.2% 91 / 102 Branchbran 64.1% 50 / 78 Conditioncond 52.1% 12 / 23 MC/DCmcdc 15.3% 2 / 13 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 72.8% 164 / 225 CC 52 SCAR 43.1
CC
52
Cov
75%
_is_false_positive
93.2
filter
5.0
count_filtered
3.1
CRAP 74.6
« Review.pm ↑ Summary Review/Tools.pm »
1 package Claude::Agent::Code::Review::Filter;
2  
3 4 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 12 ▶sub filter {
Subroutine filter: called CC=5 SCAR=16.1
Pod documented
10 12 my ($class, %args) = @_;
11  
12 12 ▶ my $issues = $args{issues} // [];
Condition50%1/2
$args{"issues"} // []
l!l
120
MC/DC0%0/1
$args{"issues"} // []
$args{"issues"}
Truth table50%1/2
A
A= $args{"issues"}
Aresult
11
00
13 12 ▶ my $filters = $args{filters} // [];
Condition100%2/2
$args{"filters"} // []
l!l
111
MC/DC100%1/1
$args{"filters"} // []
$args{"filters"}
Truth table100%2/2
A
A= $args{"filters"}
Aresult
11
00
14 12 my @filtered;
15  
16 12 for my $issue (@$issues) {
17 13 ▶ next if $class->_is_false_positive($issue, $filters);
Branch: 1 branch
BranchTrueFalseTotal
if $class->_is_false_positive($issue, $filters) 10 3 13
18 3 push @filtered, $issue;
19 }
20  
21 12 return @filtered;
22 }
23  
24 13 ▶sub _is_false_positive {
Subroutine _is_false_positive: called CC=46 SCAR=45.3
25 13 my ($class, $issue, $custom_filters) = @_;
26 13 ▶ $custom_filters //= [];
Condition50%1/2
$custom_filters //= []
l!l
130
MC/DC0%0/1
$custom_filters //= []
$custom_filters
Truth table50%1/2
A
A= $custom_filters
Aresult
11
00
27  
28 13 my $file = $issue->file;
29 13 my $line = $issue->line;
30 13 ▶ my $desc = $issue->description // '';
Condition50%1/2
$issue->description // ""
l!l
130
MC/DC0%0/1
$issue->description // ""
$issue->description
Truth table50%1/2
A
A= $issue->description
Aresult
11
00
31  
32 13 ▶ return 0 unless -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 1 12 13
33  
34 12 my $file_path = path($file);
35 12 my $safe_path = eval { $file_path->realpath };
36 12 ▶ return 0 unless $safe_path;
Branch: 1 branch
BranchTrueFalseTotal
unless $safe_path 0 12 12
37  
38 12 my $base_dir = path('.')->realpath;
39 12 ▶ return 0 unless $base_dir->subsumes($safe_path);
Branch: 1 branch
BranchTrueFalseTotal
unless $base_dir->subsumes($safe_path) 0 12 12
40  
41 12 ▶ my $content = eval { $safe_path->slurp_utf8 } // '';
Condition50%1/2
eval { do { $safe_path->slurp_utf8 } } // ""
l!l
120
MC/DC0%0/1
eval { do { $safe_path->slurp_utf8 } } // ""
eval { do { $safe_path->slurp_utf8 } }
Truth table50%1/2
A
A= eval { do { $safe_path->slurp_utf8 } }
Aresult
11
00
42 12 my @lines = split /\n/, $content;
43  
44 12 my $line_idx = $line - 1;
45 12 ▶ return 0 if $line_idx < 0 || $line_idx >= scalar(@lines);
Branch: 1 branch
BranchTrueFalseTotal
if $line_idx < 0 or $line_idx >= scalar @lines 1 11 12
Condition66%2/3
$line_idx < 0 or $line_idx >= scalar @lines
l!l&&r!l&&!r
0111
MC/DC50%1/2
$line_idx < 0 or $line_idx >= scalar @lines
$line_idx < 0 $line_idx >= scalar @lines
Truth table66%2/3
A or B
A= $line_idx < 0B= $line_idx >= scalar @lines
ABresult
1X1
011
000
46 11 my $start = $line_idx - 5;
47 11 ▶ $start = 0 if $start < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $start < 0 9 2 11
48 11 my $end = $line_idx + 5;
49 11 ▶ $end = $#lines if $end > $#lines;
Branch: 1 branch
BranchTrueFalseTotal
if $end > $#lines 5 6 11
50  
51 11 my $context = join("\n", @lines[$start..$end]);
52  
53 11 for my $filter (@$custom_filters) {
54 2 ▶ return 1 if $filter->($issue, $context);
Branch: 1 branch
BranchTrueFalseTotal
if &$filter($issue, $context) 1 1 2
55 }
56  
57 10 ▶ if ($desc =~ /heredoc|alarm|Windows|MSWin32|ReDoS|cross-platform/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc =~ /heredoc|alarm|Windows|MSWin32|ReDoS|cross-platform/iu) 1 9 10
58 1 my $wide_start = $line_idx - 15;
59 1 ▶ $wide_start = 0 if $wide_start < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $wide_start < 0 1 0 1
60 1 my $wide_end = $line_idx + 10;
61 1 ▶ $wide_end = $#lines if $wide_end > $#lines;
Branch: 1 branch
BranchTrueFalseTotal
if $wide_end > $#lines 1 0 1
62 1 my $wide_context = join("\n", @lines[$wide_start..$wide_end]);
63  
64 1 ▶ if ($wide_context =~ /Note:|TODO:|FIXME:|limitation|basic|doesn't handle|Windows:|MSWin32|fallback|rely on/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wide_context =~ /Note:|TODO:|FIXME:|limitation|basic|doesn't handle|Windows:|MSWin32|fallback|rely on/iu) 1 0 1
65 1 return 1;
66 }
67 }
68  
69 9 ▶ if ($desc =~ /unused.*import|import.*unused/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc =~ /unused.*import|import.*unused/iu) 1 8 9
70 1 ▶ if ($desc =~ /['"](\w+)['"]|\b(\w+)\s+is\s+imported/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc =~ /['"](\w+)['"]|\b(\w+)\s+is\s+imported/iu) 1 0 1
71 1 ▶ my $symbol = $1 // $2;
Condition33%1/3
$1 // $2
l!l&&r!l&&!r
100
MC/DC0%0/2
$1 // $2
$1 $2
Truth table33%1/3
A // B
A= $1B= $2
ABresult
1X1
011
000
72 1 ▶ if ($symbol && $content =~ /\b\Q$symbol\E\b/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($symbol and $content =~ /\b\Q$symbol\E\b/u) 1 0 1
Condition33%1/3
$symbol and $content =~ /\b\Q$symbol\E\b/u
!ll&&!rl&&r
001
MC/DC0%0/2
$symbol and $content =~ /\b\Q$symbol\E\b/u
$symbol $content =~ /\b\Q$symbol\E\b/u
Truth table33%1/3
A and B
A= $symbolB= $content =~ /\b\Q$symbol\E\b/u
ABresult
0X0
100
111
73 1 return 1;
74 }
75 }
76 }
77  
78 8 ▶ if ($desc =~ /no critic.*obsolete|directive.*unnecessary/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc =~ /no critic.*obsolete|directive.*unnecessary/iu) 1 7 8
79 1 ▶ if ($context =~ /##\s*no\s*critic/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context =~ /##\s*no\s*critic/iu) 1 0 1
80 1 return 1;
81 }
82 }
83  
84 7 ▶ if ($desc =~ /does.*not.*end.*with.*1|RequireEndWithOne/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc =~ /does.*not.*end.*with.*1|RequireEndWithOne/iu) 1 6 7
85 1 ▶ if ($content =~ /\n1;\s*\n?\s*$/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /\n1;\s*\n?\s*$/su) 1 0 1
86 1 return 1;
87 }
88 }
89  
90 6 ▶ if ($desc =~ /path.*validation|path.*traversal/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc =~ /path.*validation|path.*traversal/iu) 1 5 6
91 1 ▶ if ($context =~ /realpath|subsumes|base_dir/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context =~ /realpath|subsumes|base_dir/iu) 1 0 1
92 1 return 1;
93 }
94 }
95  
96 5 ▶ if ($desc =~ /missing.*error|no.*error.*handling/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc =~ /missing.*error|no.*error.*handling/iu) 1 4 5
97 1 ▶ if ($context =~ /eval\s*\{|or\s+die|\/\/|warn\s+/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context =~ m[eval\s*\{|or\s+die|//|warn\s+]iu) 1 0 1
98 1 return 1;
99 }
100 }
101  
102 4 ▶ if ($desc =~ /silent.*fail|silently/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc =~ /silent.*fail|silently/iu) 1 3 4
103 1 ▶ if ($context =~ /warn\s+["']|warn\s+\$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context =~ /warn\s+["']|warn\s+\$/iu) 1 0 1
104 1 return 1;
105 }
106 }
107  
108 3 ▶ if ($desc =~ /validation.*(?:regex|pattern|string)|(?:regex|pattern).*validation/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc =~ /validation.*(?:regex|pattern|string)|(?:regex|pattern).*validation/iu) 0 3 3
109 0 ▶ if ($context =~ /die\s+["']Invalid|Must be/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context =~ /die\s+["']Invalid|Must be/iu) 0 0 0
110 0 return 1;
111 }
112 }
113  
114 3 ▶ if ($desc =~ /off-by-one|indexing|1-based|0-based/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc =~ /off-by-one|indexing|1-based|0-based/iu) 0 3 3
115 0 ▶ if ($context =~ /\$start\s*=\s*0\s+if|\$end\s*=.*if|< 0|> \$#/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context =~ /\$start\s*=\s*0\s+if|\$end\s*=.*if|< 0|> \$#/iu) 0 0 0
116 0 return 1;
117 }
118 }
119  
120 3 ▶ if ($desc =~ /inconsistent.*(?:pattern|style|handling)|(?:pattern|style).*inconsistent/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc =~ /inconsistent.*(?:pattern|style|handling)|(?:pattern|style).*inconsistent/iu) 1 2 3
121 1 return 1;
122 }
123  
124 2 ▶ if ($desc =~ /TOCTOU|time.of.check|race.condition.*file/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc =~ /TOCTOU|time.of.check|race.condition.*file/iu) 1 1 2
125 1 ▶ if ($context =~ /Note:|TOCTOU|handles.*gracefully|handles.*missing/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context =~ /Note:|TOCTOU|handles.*gracefully|handles.*missing/iu) 1 0 1
126 1 return 1;
127 }
128 }
129  
130 1 ▶ if ($desc =~ /false.positive.*(?:filter|broad|aggressive)|(?:filter|filtering).*(?:broad|aggressive|too)/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc =~ /false.positive.*(?:filter|broad|aggressive)|(?:filter|filtering).*(?:broad|aggressive|too)/iu) 0 1 1
131 0 return 1;
132 }
133  
134 1 ▶ if ($desc =~ /(?:comment|documentation).*(?:unnecessary|redundant|obvious)/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc =~ /(?:comment|documentation).*(?:unnecessary|redundant|obvious)/iu) 0 1 1
135 0 return 1;
136 }
137  
138 1 ▶ if ($desc =~ /no.critic.*(?:directive|issue|apply|not.*needed)|directive.*no.critic/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc =~ /no.critic.*(?:directive|issue|apply|not.*needed)|directive.*no.critic/iu) 0 1 1
139 0 return 1;
140 }
141  
142 1 ▶ if ($desc =~ /position.*(?:fragile|incorrect)|(?:fragile|incorrect).*position|length\(\).*position/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc =~ /position.*(?:fragile|incorrect)|(?:fragile|incorrect).*position|length\(\).*position/iu) 0 1 1
143 0 ▶ if ($context =~ /length\(\$\w+\)\s*<\s*length\(\$\w+\)/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context =~ /length\(\$\w+\)\s*<\s*length\(\$\w+\)/iu) 0 0 0
144 0 return 1;
145 }
146 }
147  
148 1 ▶ if ($desc =~ /regex.*(?:edge|corner|doesn't capture|doesn't handle)|(?:edge|corner).*case/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc =~ /regex.*(?:edge|corner|doesn't capture|doesn't handle)|(?:edge|corner).*case/iu) 0 1 1
149 0 ▶ if ($context =~ /\# .*(?:handle|capture|parse)|TODO|basic/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context =~ /\# .*(?:handle|capture|parse)|TODO|basic/iu) 0 0 0
150 0 return 1;
151 }
152 }
153  
154 1 return 0;
155 }
156  
157 1 ▶sub count_filtered {
Subroutine count_filtered: called CC=3 SCAR=11.2
Pod documented
158 1 my ($class, %args) = @_;
159  
160 1 ▶ my $original = scalar @{$args{original} // []};
Condition50%1/2
$args{"original"} // []
l!l
10
MC/DC0%0/1
$args{"original"} // []
$args{"original"}
Truth table50%1/2
A
A= $args{"original"}
Aresult
11
00
161 1 ▶ my $filtered = scalar @{$args{filtered} // []};
Condition50%1/2
$args{"filtered"} // []
l!l
10
MC/DC0%0/1
$args{"filtered"} // []
$args{"filtered"}
Truth table50%1/2
A
A= $args{"filtered"}
Aresult
11
00
162  
163 1 return ($filtered, $original - $filtered);
164 }
165  
166  
167 4 1;
168  
169 __END__
« Review.pm ↑ Summary Review/Tools.pm »