« Perl/Lint/Policy/TestingAndDebugging/ProhibitNoStrict.pm
↑ Summary
Perl/Lint/Policy/InputOutput/ProhibitReadlineInForLoop.pm »
| 1 | package Perl::Lint::Policy::RegularExpressions::ProhibitComplexRegexes; | ||||||||||||||||||||||||||||||||||||||||||
| 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 => 'Split long regexps into smaller qr// chunks', | |||||||||||||||||||||||||||||||||||||||||
| 9 | EXPL => [261], | ||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | sub evaluate { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evaluate: not called CC=16 SCAR=56.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | my ($class, $file, $tokens, $src, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | my $max_characters = $args->{prohibit_complex_regexes}->{max_characters} || 60; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'prohibit_complex_regexes'}{'max_characters'} || 60
MC/DC0%0/1
$args->{'prohibit_complex_regexes'}{'max_characters'} || 60
$args->{'prohibit_complex_regexes'}{'max_characters'}
Truth table0%0/2
A
A= $args->{'prohibit_complex_regexes'}{'max_characters'}
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | my @violations; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | my $is_reg_quote = 0; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | my $is_delimiter_single_quote = 0; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | for (my $i = 0, my $token_type, my $token_data; my $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | $token_data = $token->{data}; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | if ($token_type == REG_DELIM) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | if ($token_data eq q{'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | $is_delimiter_single_quote = 1; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||
| 29 | elsif ($token_type == REG_EXP) { | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | my $regexp = $token_data; | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my $_is_delimiter_single_quote = $is_delimiter_single_quote; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | $is_delimiter_single_quote = 0; | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $_is_reg_quote = $is_reg_quote; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | $is_reg_quote = 0; | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if ($_is_reg_quote) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | # ignore when reg quote | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if (!$_is_delimiter_single_quote) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | # replace variables | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | while ($regexp =~ /(\\*)([\$\@]\S+)/gc) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if (length($1) % 2 == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | # not escaped | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $regexp =~ s/(\\*)[\$\@]\S+/$1xxxx/; # replace the variable to no-meaning 4 characters string | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | # escaped | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | $regexp =~ s/(\\*)[\$\@]/$1X/; # replace the sigil to no-meaning character | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $maybe_regopt = $tokens->[$i+2]; # XXX right!? | |||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$maybe_regopt and $maybe_regopt->{"type"} == 144 and $maybe_regopt->{"data"} =~ /x/
$maybe_regopt and $maybe_regopt->{"type"} == 144
MC/DC0%0/3
$maybe_regopt and $maybe_regopt->{"type"} == 144 and $maybe_regopt->{"data"} =~ /x/
$maybe_regopt
$maybe_regopt->{"type"} == 144
$maybe_regopt->{"data"} =~ /x/
Truth table0%0/4
A and B and C
A= $maybe_regoptB= $maybe_regopt->{"type"} == 144C= $maybe_regopt->{"data"} =~ /x/
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | $maybe_regopt && | ||||||||||||||||||||||||||||||||||||||||||
| 60 | $maybe_regopt->{type} == REG_OPT && | ||||||||||||||||||||||||||||||||||||||||||
| 61 | $maybe_regopt->{data} =~ /x/ | ||||||||||||||||||||||||||||||||||||||||||
| 62 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $regexp =~ s/#.*?\n//gs; # reduce comments | |||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $regexp =~ s/\s//g; # reduce white spaces | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if (length $regexp > $max_characters) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | push @violations, { | ||||||||||||||||||||||||||||||||||||||||||
| 69 | filename => $file, | ||||||||||||||||||||||||||||||||||||||||||
| 70 | line => $token->{line}, | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | description => DESC, | |||||||||||||||||||||||||||||||||||||||||
| 72 | explanation => EXPL, | ||||||||||||||||||||||||||||||||||||||||||
| 73 | policy => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||
| 74 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | ▶ | elsif ($token_type == REG_QUOTE || $token_type == REG_DOUBLE_QUOTE) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$token_type == 145 or $token_type == 146
MC/DC0%0/2
$token_type == 145 or $token_type == 146
$token_type == 145
$token_type == 146
Truth table0%0/3
A or B
A= $token_type == 145B= $token_type == 146
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $is_reg_quote = 1; | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | return \@violations; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||