Perl/Lint/Policy/BuiltinFunctions/ProhibitUselessTopic.pm

filter: Statementstmt 70.1% 40 / 57 Branchbran 37.5% 12 / 32 Conditioncond 16.6% 5 / 30 MC/DCmcdc 6.2% 1 / 16 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 45.8% 66 / 144 CC 27 SCAR 51.5
CC
27
Cov
48%
evaluate
217.4
BEGIN
1.0
BEGIN
1.0
CRAP 172.8
« Perl/Lint/Policy/Variables/ProhibitLocalVars.pm ↑ Summary Perl/Lint/Policy/BuiltinFunctions/ProhibitReverseSortBlock.pm »
1 package Perl::Lint::Policy::BuiltinFunctions::ProhibitUselessTopic;
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 Perl::Lint::Constants::Kind;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 DESC => 'Useless use of $_',
10 EXPL_FILETEST => '$_ should be omitted when using a filetest operator',
11 EXPL_FUNCTION => '$_ should be omitted when calling "%s"',
12 EXPL_FUNCTION_SPLIT => '$_ should be omitted when calling "split" with two arguments',
13 3 };
14  
15 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 FILETEST_OPERATORS => {
17 -r => 1,
18 -w => 1,
19 -x => 1,
20 -o => 1,
21 -R => 1,
22 -W => 1,
23 -X => 1,
24 -O => 1,
25 -e => 1,
26 -z => 1,
27 -s => 1,
28 -f => 1,
29 -d => 1,
30 -l => 1,
31 -p => 1,
32 -S => 1,
33 -b => 1,
34 -c => 1,
35 -u => 1,
36 -g => 1,
37 -k => 1,
38 -T => 1,
39 -B => 1,
40 -M => 1,
41 -A => 1,
42 -C => 1,
43 },
44 TOPICAL_FUNCS => {
45 abs => 1,
46 alarm => 1,
47 chomp => 1,
48 chop => 1,
49 chr => 1,
50 chroot => 1,
51 cos => 1,
52 defined => 1,
53 eval => 1,
54 exp => 1,
55 glob => 1,
56 hex => 1,
57 int => 1,
58 lc => 1,
59 lcfirst => 1,
60 length => 1,
61 log => 1,
62 lstat => 1,
63 mkdir => 1,
64 oct => 1,
65 ord => 1,
66 pos => 1,
67 print => 1,
68 quotemeta => 1,
69 readlink => 1,
70 readpipe => 1,
71 ref => 1,
72 require => 1,
73 reverse => 1,
74 rmdir => 1,
75 sin => 1,
76 split => 1,
77 sqrt => 1,
78 stat => 1,
79 study => 1,
80 uc => 1,
81 ucfirst => 1,
82 unlink => 1,
83 unpack => 1,
84 },
85 3 };
86  
87 2 ▶sub evaluate {
Subroutine evaluate: called CC=27 SCAR=53.8
Pod undocumented
88 2 my ($class, $file, $tokens, $src, $args) = @_;
89  
90 2 my @violations;
91 2 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 49 2 51
92 49 my $token_type = $token->{type};
93 49 my $token_data = $token->{data};
94  
95 49 ▶ if ($token_type == HANDLE && FILETEST_OPERATORS->{$token_data}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 89 and {-A => 1, -B => 1, -C => 1, -M => 1, -O => 1, -R => 1, -S => 1, -T => 1, -W => 1, -X => 1, -b => 1, -c => 1, -d => 1, -e => 1, -f => 1, -g => 1, -k => 1, -l => 1, -o => 1, -p => 1, -r => 1, -s => 1, -u => 1, -w => 1, -x => 1, -z => 1}->{$token_data}) { } 0 49 49
elsif ($token_type == 70 and {abs => 1, alarm => 1, chomp => 1, chop => 1, chr => 1, chroot => 1, cos => 1, defined => 1, eval => 1, exp => 1, glob => 1, hex => 1, int => 1, lc => 1, lcfirst => 1, length => 1, log => 1, lstat => 1, mkdir => 1, oct => 1, ord => 1, pos => 1, print => 1, quotemeta => 1, readlink => 1, readpipe => 1, ref => 1, require => 1, reverse => 1, rmdir => 1, sin => 1, split => 1, sqrt => 1, stat => 1, study => 1, uc => 1, ucfirst => 1, unlink => 1, unpack => 1}->{$token_data}) { } 1 96 97
Condition33%1/3
$token_type == 89 and {"-A" => 1,"-B" => 1,"-C" => 1,"-M" => 1,"-O" => 1,"-R" => 1,"-S" => 1,"-T" => 1,"-W" => 1,"-X" => 1,"-b" => 1,"-c" => 1,"-d" => 1,"-e" => 1,"-f" => 1,"-g" => 1,"-k" => 1,"-l" => 1,"-o" => 1,"-p" => 1,"-r" => 1,"-s" => 1,"-u" => 1,"-w" => 1,"-x" => 1,"-z" => 1}->{$token_data}
!ll&&!rl&&r
4900
MC/DC0%0/2
$token_type == 89 and {"-A" => 1,"-B" => 1,"-C" => 1,"-M" => 1,"-O" => 1,"-R" => 1,"-S" => 1,"-T" => 1,"-W" => 1,"-X" => 1,"-b" => 1,"-c" => 1,"-d" => 1,"-e" => 1,"-f" => 1,"-g" => 1,"-k" => 1,"-l" => 1,"-o" => 1,"-p" => 1,"-r" => 1,"-s" => 1,"-u" => 1,"-w" => 1,"-x" => 1,"-z" => 1}->{$token_data}
$token_type == 89 {"-A" => 1,"-B" => 1,"-C" => 1,"-M" => 1,"-O" => 1,"-R" => 1,"-S" => 1,"-T" => 1,"-W" => 1,"-X" => 1,"-b" => 1,"-c" => 1,"-d" => 1,"-e" => 1,"-f" => 1,"-g" => 1,"-k" => 1,"-l" => 1,"-o" => 1,"-p" => 1,"-r" => 1,"-s" => 1,"-u" => 1,"-w" => 1,"-x" => 1,"-z" => 1}->{$token_data}
Truth table33%1/3
A and B
A= $token_type == 89B= {"-A" => 1,"-B" => 1,"-C" => 1,"-M" => 1,"-O" => 1,"-R" => 1,"-S" => 1,"-T" => 1,"-W" => 1,"-X" => 1,"-b" => 1,"-c" => 1,"-d" => 1,"-e" => 1,"-f" => 1,"-g" => 1,"-k" => 1,"-l" => 1,"-o" => 1,"-p" => 1,"-r" => 1,"-s" => 1,"-u" => 1,"-w" => 1,"-x" => 1,"-z" => 1}->{$token_data}
ABresult
0X0
100
111
96 0 $token = $tokens->[++$i];
97 0 ▶ if ($token->{type} == SPECIFIC_VALUE && $token->{data} eq '$_') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} == 137 and $token->{"data"} eq "\$_") 0 0 0
Condition0%0/3
$token->{"type"} == 137 and $token->{"data"} eq "\$_"
!ll&&!rl&&r
000
MC/DC0%0/2
$token->{"type"} == 137 and $token->{"data"} eq "\$_"
$token->{"type"} == 137 $token->{"data"} eq "\$_"
Truth table0%0/3
A and B
A= $token->{"type"} == 137B= $token->{"data"} eq "\$_"
ABresult
0X0
100
111
98 push @violations, {
99 filename => $file,
100 line => $token->{line},
101 0 description => DESC,
102 explanation => EXPL_FILETEST,
103 policy => __PACKAGE__,
104 };
105 }
106 }
107 ▶ elsif ($token_type == BUILTIN_FUNC && TOPICAL_FUNCS->{$token_data}) {
Condition66%2/3
$token_type == 70 and {"abs" => 1,"alarm" => 1,"chomp" => 1,"chop" => 1,"chr" => 1,"chroot" => 1,"cos" => 1,"defined" => 1,"eval" => 1,"exp" => 1,"glob" => 1,"hex" => 1,"int" => 1,"lc" => 1,"lcfirst" => 1,"length" => 1,"log" => 1,"lstat" => 1,"mkdir" => 1,"oct" => 1,"ord" => 1,"pos" => 1,"print" => 1,"quotemeta" => 1,"readlink" => 1,"readpipe" => 1,"ref" => 1,"require" => 1,"reverse" => 1,"rmdir" => 1,"sin" => 1,"split" => 1,"sqrt" => 1,"stat" => 1,"study" => 1,"uc" => 1,"ucfirst" => 1,"unlink" => 1,"unpack" => 1}->{$token_data}
!ll&&!rl&&r
4801
MC/DC50%1/2
$token_type == 70 and {"abs" => 1,"alarm" => 1,"chomp" => 1,"chop" => 1,"chr" => 1,"chroot" => 1,"cos" => 1,"defined" => 1,"eval" => 1,"exp" => 1,"glob" => 1,"hex" => 1,"int" => 1,"lc" => 1,"lcfirst" => 1,"length" => 1,"log" => 1,"lstat" => 1,"mkdir" => 1,"oct" => 1,"ord" => 1,"pos" => 1,"print" => 1,"quotemeta" => 1,"readlink" => 1,"readpipe" => 1,"ref" => 1,"require" => 1,"reverse" => 1,"rmdir" => 1,"sin" => 1,"split" => 1,"sqrt" => 1,"stat" => 1,"study" => 1,"uc" => 1,"ucfirst" => 1,"unlink" => 1,"unpack" => 1}->{$token_data}
$token_type == 70 {"abs" => 1,"alarm" => 1,"chomp" => 1,"chop" => 1,"chr" => 1,"chroot" => 1,"cos" => 1,"defined" => 1,"eval" => 1,"exp" => 1,"glob" => 1,"hex" => 1,"int" => 1,"lc" => 1,"lcfirst" => 1,"length" => 1,"log" => 1,"lstat" => 1,"mkdir" => 1,"oct" => 1,"ord" => 1,"pos" => 1,"print" => 1,"quotemeta" => 1,"readlink" => 1,"readpipe" => 1,"ref" => 1,"require" => 1,"reverse" => 1,"rmdir" => 1,"sin" => 1,"split" => 1,"sqrt" => 1,"stat" => 1,"study" => 1,"uc" => 1,"ucfirst" => 1,"unlink" => 1,"unpack" => 1}->{$token_data}
Truth table66%2/3
A and B
A= $token_type == 70B= {"abs" => 1,"alarm" => 1,"chomp" => 1,"chop" => 1,"chr" => 1,"chroot" => 1,"cos" => 1,"defined" => 1,"eval" => 1,"exp" => 1,"glob" => 1,"hex" => 1,"int" => 1,"lc" => 1,"lcfirst" => 1,"length" => 1,"log" => 1,"lstat" => 1,"mkdir" => 1,"oct" => 1,"ord" => 1,"pos" => 1,"print" => 1,"quotemeta" => 1,"readlink" => 1,"readpipe" => 1,"ref" => 1,"require" => 1,"reverse" => 1,"rmdir" => 1,"sin" => 1,"split" => 1,"sqrt" => 1,"stat" => 1,"study" => 1,"uc" => 1,"ucfirst" => 1,"unlink" => 1,"unpack" => 1}->{$token_data}
ABresult
0X0
100
111
108 # Ignore when reverse() called in context of assigning into array
109 1 my $function_name = $token_data;
110 1 ▶ if ($function_name eq 'reverse') {
Branch: 1 branch
BranchTrueFalseTotal
if ($function_name eq "reverse") 0 1 1
111 0 my $two_before_token_type = $tokens->[$i-2]->{type};
112 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($$tokens[$i - 1]{"type"} == 65 and $two_before_token_type == 168 || $two_before_token_type == 192 || $two_before_token_type == 195) 0 0 0
Condition0%0/9
$$tokens[$i - 1]{"type"} == 65 and $two_before_token_type == 168 || $two_before_token_type == 192 || $two_before_token_type == 195
!ll&&!rl&&r
000
$two_before_token_type == 168 or $two_before_token_type == 192 or $two_before_token_type == 195
l!l&&r!l&&!r
000
$two_before_token_type == 168 or $two_before_token_type == 192
l!l&&r!l&&!r
000
MC/DC0%0/4
$$tokens[$i - 1]{"type"} == 65 and $two_before_token_type == 168 || $two_before_token_type == 192 || $two_before_token_type == 195
$$tokens[$i - 1]{"type"} == 65 $two_before_token_type == 168 $two_before_token_type == 192 $two_before_token_type == 195
Truth table0%0/5
A and B or C or D
A= $$tokens[$i - 1]{"type"} == 65B= $two_before_token_type == 168C= $two_before_token_type == 192D= $two_before_token_type == 195
ABCDresult
0XXX0
10000
11XX1
101X1
10011
113 $tokens->[$i-1]->{type} == ASSIGN &&
114 (
115 $two_before_token_type == ARRAY_VAR ||
116 $two_before_token_type == LOCAL_ARRAY_VAR ||
117 $two_before_token_type == GLOBAL_ARRAY_VAR
118 )
119 ) {
120 0 next;
121 }
122 }
123  
124 1 ▶ my $expl = $function_name eq 'split' ? EXPL_FUNCTION_SPLIT
Branch: 1 branch
BranchTrueFalseTotal
$function_name eq 'split' ? : 0 1 1
125 : sprintf EXPL_FUNCTION, $function_name;
126  
127 1 $token = $tokens->[++$i];
128  
129 1 ▶ if ($token->{type} == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{'type'} == 107) { } 0 1 1
130 0 my $left_paren_num = 1;
131 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
132 0 $token_type = $token->{type};
133 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 108) { } 0 0 0
134 0 $left_paren_num++;
135 }
136 elsif ($token_type == RIGHT_PAREN) {
137 0 ▶ if (--$left_paren_num <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$left_paren_num <= 0) 0 0 0
138 0 my $previous_token = $tokens->[$i-1];
139 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($$tokens[$i - 2]{"kind"} != 1 and $previous_token->{"type"} == 137 and $previous_token->{"data"} eq "\$_") 0 0 0
Condition0%0/6
$$tokens[$i - 2]{"kind"} != 1 and $previous_token->{"type"} == 137 and $previous_token->{"data"} eq "\$_"
!ll&&!rl&&r
000
$$tokens[$i - 2]{"kind"} != 1 and $previous_token->{"type"} == 137
!ll&&!rl&&r
000
MC/DC0%0/3
$$tokens[$i - 2]{"kind"} != 1 and $previous_token->{"type"} == 137 and $previous_token->{"data"} eq "\$_"
$$tokens[$i - 2]{"kind"} != 1 $previous_token->{"type"} == 137 $previous_token->{"data"} eq "\$_"
Truth table0%0/4
A and B and C
A= $$tokens[$i - 2]{"kind"} != 1B= $previous_token->{"type"} == 137C= $previous_token->{"data"} eq "\$_"
ABCresult
0XX0
10X0
1100
1111
140 $tokens->[$i-2]->{kind} != KIND_OP &&
141 $previous_token->{type} == SPECIFIC_VALUE &&
142 $previous_token->{data} eq '$_'
143 ) {
144 push @violations, {
145 filename => $file,
146 line => $token->{line},
147 0 description => DESC,
148 explanation => $expl,
149 policy => __PACKAGE__,
150 };
151 }
152 }
153 0 last;
154 }
155 }
156 }
157 else {
158 1 ▶ for (; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 2 0 2
159 2 $token_type = $token->{type};
160 2 ▶ if ($token_type == SEMI_COLON) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 106) 1 1 2
161 1 my $previous_token = $tokens->[$i-1];
162 1 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($$tokens[$i - 2]{"kind"} != 1 and $previous_token->{"type"} == 137 and $previous_token->{"data"} eq "\$_") 0 1 1
Condition33%2/6
$$tokens[$i - 2]{"kind"} != 1 and $previous_token->{"type"} == 137 and $previous_token->{"data"} eq "\$_"
!ll&&!rl&&r
100
$$tokens[$i - 2]{"kind"} != 1 and $previous_token->{"type"} == 137
!ll&&!rl&&r
010
MC/DC0%0/3
$$tokens[$i - 2]{"kind"} != 1 and $previous_token->{"type"} == 137 and $previous_token->{"data"} eq "\$_"
$$tokens[$i - 2]{"kind"} != 1 $previous_token->{"type"} == 137 $previous_token->{"data"} eq "\$_"
Truth table25%1/4
A and B and C
A= $$tokens[$i - 2]{"kind"} != 1B= $previous_token->{"type"} == 137C= $previous_token->{"data"} eq "\$_"
ABCresult
0XX0
10X0
1100
1111
163 $tokens->[$i-2]->{kind} != KIND_OP &&
164 $previous_token->{type} == SPECIFIC_VALUE &&
165 $previous_token->{data} eq '$_'
166 ) {
167 push @violations, {
168 filename => $file,
169 line => $token->{line},
170 0 description => DESC,
171 explanation => $expl,
172 policy => __PACKAGE__,
173 };
174 }
175 1 last;
176 }
177 }
178 }
179 }
180 }
181  
182 2 return \@violations;
183 }
184  
185 3 1;
186  
« Perl/Lint/Policy/Variables/ProhibitLocalVars.pm ↑ Summary Perl/Lint/Policy/BuiltinFunctions/ProhibitReverseSortBlock.pm »