« 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 | ®_QUOTE => 1, | ||||||||||||||||||||||||||||||||||||
| 13 | ®_DOUBLE_QUOTE => 1, | ||||||||||||||||||||||||||||||||||||
| 14 | ®_LIST => 1, | ||||||||||||||||||||||||||||||||||||
| 15 | ®_EXEC => 1, | ||||||||||||||||||||||||||||||||||||
| 16 | ®_DECL => 1, | ||||||||||||||||||||||||||||||||||||
| 17 | ®_MATCH => 1, | ||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||
| 19 | ®_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
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 57 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||
| 58 | 0 | $token_data = $token->{data}; | |||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ($TARGET_REGS{$token_type}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 61 | 0 | $next_token = $tokens->[++$i]; | |||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ($next_token && $next_token->{type} == REG_DELIM) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$next_token and $next_token->{"type"} == 151
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
| |||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$next_token_data eq "'" and not $target_regs_allows_single_quote{$token_data}
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}
| |||||||||||||||||||||||||||||||||||||
| 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}
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}
| |||||||||||||||||||||||||||||||||||||
| 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}
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}
| |||||||||||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||||||||||