« Perl/Lint/Policy/Modules/ProhibitExcessMainComplexity.pm
↑ Summary
Perl/Lint/Policy/BuiltinFunctions/ProhibitComplexMappings.pm »
| 1 | package Perl::Lint::Policy::CodeLayout::ProhibitQuotedWordLists; | ||||||||||||||||||||||||||||||||||||||||||||||
| 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 parent "Perl::Lint::Policy"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # TODO TODO TODO integrate duplicated functions between assign context and use context !!!! | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | DESC => 'List of quoted literal words', | |||||||||||||||||||||||||||||||||||||||||||||
| 11 | EXPL => 'Use "qw()" instead', | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | sub evaluate { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evaluate: called CC=35 SCAR=65.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | my ($class, $file, $tokens, $src, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | my $min_elements = $args->{prohibit_quoted_word_lists}->{min_elements} || 2; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'prohibit_quoted_word_lists'}{'min_elements'} || 2
MC/DC0%0/1
$args->{'prohibit_quoted_word_lists'}{'min_elements'} || 2
$args->{'prohibit_quoted_word_lists'}{'min_elements'}
Truth table50%1/2
A
A= $args->{'prohibit_quoted_word_lists'}{'min_elements'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | my $strict = $args->{prohibit_quoted_word_lists}->{strict} || 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'prohibit_quoted_word_lists'}{'strict'} || 0
MC/DC0%0/1
$args->{'prohibit_quoted_word_lists'}{'strict'} || 0
$args->{'prohibit_quoted_word_lists'}{'strict'}
Truth table50%1/2
A
A= $args->{'prohibit_quoted_word_lists'}{'strict'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | my @violations; | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | for (my $i = 0; my $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 27 | my $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 27 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
$token_type == 168 or $token_type == 192 or $token_type == 195
$token_type == 168 or $token_type == 192
MC/DC0%0/3
$token_type == 168 or $token_type == 192 or $token_type == 195
$token_type == 168
$token_type == 192
$token_type == 195
Truth table25%1/4
A or B or C
A= $token_type == 168B= $token_type == 192C= $token_type == 195
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | $token_type == ARRAY_VAR || | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | $token_type == LOCAL_ARRAY_VAR || | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | $token_type == GLOBAL_ARRAY_VAR | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | $token = $tokens->[++$i]; | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | if ($token_type == ASSIGN) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | $token = $tokens->[++$i]; | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if ($token_type == LEFT_PAREN) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $left_paren_num = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my $is_violated = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $elem_num = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | for ($i++; $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ($token_type == LEFT_PAREN) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $left_paren_num++; | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | elsif ($token_type == RIGHT_PAREN) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if (--$left_paren_num <= 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if ($is_violated && $elem_num >= $min_elements) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$is_violated and $elem_num >= $min_elements
MC/DC0%0/2
$is_violated and $elem_num >= $min_elements
$is_violated
$elem_num >= $min_elements
Truth table0%0/3
A and B
A= $is_violatedB= $elem_num >= $min_elements
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | push @violations, { | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | filename => $file, | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | line => $token->{line}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | description => DESC, | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | explanation => EXPL, | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | policy => __PACKAGE__ | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | ▶ | elsif ($token_type == STRING || $token_type == RAW_STRING) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$token_type == 172 or $token_type == 173
MC/DC0%0/2
$token_type == 172 or $token_type == 173
$token_type == 172
$token_type == 173
Truth table0%0/3
A or B
A= $token_type == 172B= $token_type == 173
| |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $elem_num++; | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | next if $strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ($token->{data} !~ /\A[a-zA-Z-]+\Z/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $is_violated = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | elsif ($token_type != COMMA) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $elem_num++; | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $is_violated = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | elsif ($token_type == USE_DECL) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 8 | ▶ | USE_STATEMENT: for ($i++; $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 24 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 24 | ▶ | if ($token_type == LEFT_PAREN) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my $left_paren_num = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my $is_violated = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $elem_num = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | for ($i++; $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ($token_type == LEFT_PAREN) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $left_paren_num++; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | elsif ($token_type == RIGHT_PAREN) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if (--$left_paren_num <= 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if ($is_violated && $elem_num >= $min_elements) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$is_violated and $elem_num >= $min_elements
MC/DC0%0/2
$is_violated and $elem_num >= $min_elements
$is_violated
$elem_num >= $min_elements
Truth table0%0/3
A and B
A= $is_violatedB= $elem_num >= $min_elements
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | push @violations, { | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | filename => $file, | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | line => $token->{line}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | description => DESC, | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | explanation => EXPL, | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | policy => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | last USE_STATEMENT; | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | ▶ | elsif ($token_type == STRING || $token_type == RAW_STRING) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$token_type == 172 or $token_type == 173
MC/DC0%0/2
$token_type == 172 or $token_type == 173
$token_type == 172
$token_type == 173
Truth table0%0/3
A or B
A= $token_type == 172B= $token_type == 173
| |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $elem_num++; | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | next if $strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ($token->{data} !~ /\A[a-zA-Z-]+\Z/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $is_violated = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | elsif ($token_type != COMMA) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $elem_num++; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $is_violated = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | elsif ($token_type == SEMI_COLON) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 8 | last; | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 2 | return \@violations; | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||