Perl/Lint/Policy/ValuesAndExpressions/ProhibitQuotesAsQuotelikeOperatorDelimiters.pm

filter: Statementstmt 36.1% 17 / 47 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 23.9% 22 / 92 CC 17 SCAR 54.7
CC
17
Cov
22%
evaluate
306.0
BEGIN
1.0
BEGIN
1.0
CRAP 236.7
« Perl/Lint/Policy/Variables/ProhibitConditionalDeclarations.pm ↑ Summary Perl/Lint/Policy/BuiltinFunctions/ProhibitBooleanGrep.pm »
1 package Perl::Lint::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters;
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 EXPL => 'Using quotes as delimiters for quote-like operators obfuscates code',
9 2 };
10  
11 2 my %TARGET_REGS = (
12 &REG_QUOTE => 1,
13 &REG_DOUBLE_QUOTE => 1,
14 &REG_LIST => 1,
15 &REG_EXEC => 1,
16 &REG_DECL => 1,
17 &REG_MATCH => 1,
18  
19 &REG_ALL_REPLACE => 1,
20 );
21  
22 # TODO operator which has `replace from` and `replace to` doesn't work certainly.
23 # It maybe caused by Compiler::Lexer's bug.
24  
25 0 ▶sub evaluate {
Subroutine evaluate: not called CC=17 SCAR=57.2
Pod undocumented
26 0 my ($class, $file, $tokens, $src, $args) = @_;
27  
28 0 my %target_regs_allows_single_quote = (
29 'qx' => 1,
30 'qr' => 1,
31 'm' => 1,
32 );
33 0 ▶ if (defined (my $single_quote_allowed_operators = $args->{single_quote_allowed_operators})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $single_quote_allowed_operators = $args->{"single_quote_allowed_operators"})) 0 0 0
34 0 %target_regs_allows_single_quote = ();
35 0 for my $allow_delim (split qr/\s+/, $single_quote_allowed_operators) {
36 0 $target_regs_allows_single_quote{$allow_delim} = 1;
37 }
38 }
39  
40 0 my %target_regs_allows_double_quote = ();
41 0 ▶ if (defined (my $double_quote_allowed_operators = $args->{double_quote_allowed_operators})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $double_quote_allowed_operators = $args->{"double_quote_allowed_operators"})) 0 0 0
42 0 for my $allow_delim (split qr/\s+/, $double_quote_allowed_operators) {
43 0 $target_regs_allows_double_quote{$allow_delim} = 1;
44 }
45 }
46  
47 0 my %target_regs_allows_back_quote = ();
48 0 ▶ if (defined (my $back_quote_allowed_operators = $args->{back_quote_allowed_operators})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $back_quote_allowed_operators = $args->{"back_quote_allowed_operators"})) 0 0 0
49 0 for my $allow_delim (split qr/\s+/, $back_quote_allowed_operators) {
50 0 $target_regs_allows_back_quote{$allow_delim} = 1;
51 }
52 }
53  
54 0 my @violations;
55 my $next_token;
56 0 ▶ for (my $i = 0, my $token_type, my $token_data; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
57 0 $token_type = $token->{type};
58 0 $token_data = $token->{data};
59  
60 0 ▶ if ($TARGET_REGS{$token_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($TARGET_REGS{$token_type}) 0 0 0
61 0 $next_token = $tokens->[++$i];
62 0 ▶ if ($next_token && $next_token->{type} == REG_DELIM) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token and $next_token->{"type"} == 151) 0 0 0
Condition0%0/3
$next_token and $next_token->{"type"} == 151
!ll&&!rl&&r
000
MC/DC0%0/2
$next_token and $next_token->{"type"} == 151
$next_token $next_token->{"type"} == 151
Truth table0%0/3
A and B
A= $next_tokenB= $next_token->{"type"} == 151
ABresult
0X0
100
111
63 0 my $next_token_data= $next_token->{data};
64  
65 0 my $desc = '';
66 0 ▶ if ($next_token_data eq q<'> && !$target_regs_allows_single_quote{$token_data}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($next_token_data eq q['] and not $target_regs_allows_single_quote{$token_data}) { } 0 0 0
elsif ($next_token_data eq '"' and not $target_regs_allows_double_quote{$token_data}) { } 0 0 0
elsif ($next_token_data eq '`' and not $target_regs_allows_back_quote{$token_data}) { } 0 0 0
Condition0%0/3
$next_token_data eq "'" and not $target_regs_allows_single_quote{$token_data}
!ll&&!rl&&r
000
MC/DC0%0/2
$next_token_data eq "'" and not $target_regs_allows_single_quote{$token_data}
$next_token_data eq "'" not $target_regs_allows_single_quote{$token_data}
Truth table0%0/3
A and not(B)
A= $next_token_data eq "'"B= not $target_regs_allows_single_quote{$token_data}
ABresult
0X0
100
111
67 0 $desc= 'Single-quote used as quote-like operator delimiter';
68 }
69 ▶ elsif ($next_token_data eq q<"> && !$target_regs_allows_double_quote{$token_data}) {
Condition0%0/3
$next_token_data eq "\"" and not $target_regs_allows_double_quote{$token_data}
!ll&&!rl&&r
000
MC/DC0%0/2
$next_token_data eq "\"" and not $target_regs_allows_double_quote{$token_data}
$next_token_data eq "\"" not $target_regs_allows_double_quote{$token_data}
Truth table0%0/3
A and not(B)
A= $next_token_data eq "\""B= not $target_regs_allows_double_quote{$token_data}
ABresult
0X0
100
111
70 0 $desc = 'Double-quote used as quote-like operator delimiter';
71 }
72 ▶ elsif ($next_token_data eq q<`> && !$target_regs_allows_back_quote{$token_data}) {
Condition0%0/3
$next_token_data eq "`" and not $target_regs_allows_back_quote{$token_data}
!ll&&!rl&&r
000
MC/DC0%0/2
$next_token_data eq "`" and not $target_regs_allows_back_quote{$token_data}
$next_token_data eq "`" not $target_regs_allows_back_quote{$token_data}
Truth table0%0/3
A and not(B)
A= $next_token_data eq "`"B= not $target_regs_allows_back_quote{$token_data}
ABresult
0X0
100
111
73 0 $desc = 'Back-quote (back-tick) used as quote-like operator delimiter';
74 }
75 else {
76 0 next;
77 }
78  
79 push @violations, {
80 filename => $file,
81 line => $next_token->{line},
82 0 description => $desc,
83 explanation => EXPL,
84 policy => __PACKAGE__,
85 };
86 }
87 }
88 }
89  
90 0 return \@violations;
91 }
92  
93 2 1;
94  
« Perl/Lint/Policy/Variables/ProhibitConditionalDeclarations.pm ↑ Summary Perl/Lint/Policy/BuiltinFunctions/ProhibitBooleanGrep.pm »