« Perl/Lint/Policy/ControlStructures/ProhibitDeepNests.pm
↑ Summary
Perl/Lint/Policy/Variables/ProhibitMatchVars.pm »
| 1 | package Perl::Lint::Policy::BuiltinFunctions::ProhibitVoidMap; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | # TODO REFACTOR!!! | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | DESC => '"map" used in void context', | |||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | EXPL => 'Use a "for" loop instead', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub evaluate { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evaluate: not called CC=20 SCAR=60.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | my ($class, $file, $tokens, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | my @violations; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | my $is_in_context = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | my $is_before_comma = 0; # XXX to decide is in context or not | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | my $is_in_map = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | my $is_in_ctrl_statement = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | my $left_brace_num = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | for (my $i = 0; my $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my $token_data = $token->{data}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | if ($token_type == BUILTIN_FUNC) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | if ($token_data eq 'map') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | next if $is_in_map; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | if ($is_in_ctrl_statement) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | if ($left_brace_num) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | push @violations, { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | filename => $file, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | line => $token->{line}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | description => DESC, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | explanation => EXPL, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | policy => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ▶ | elsif (!$is_in_context && !$is_before_comma) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$is_in_context || $is_before_comma
MC/DC0%0/2
$is_in_context || $is_before_comma
$is_in_context
$is_before_comma
Truth table0%0/3
A || B
A= $is_in_contextB= $is_before_comma
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | push @violations, { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | filename => $file, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | line => $token->{line}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | description => DESC, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | explanation => EXPL, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | policy => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $is_in_map = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $is_in_context = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | elsif ($token_type == ASSIGN) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | $is_in_context = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | ▶ | elsif ( # NOTE enough? | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
$token_type == 96 or $token_type == 133 or $token_type == 132 or $token_type == 99
$token_type == 96 or $token_type == 133 or $token_type == 132
$token_type == 96 or $token_type == 133
MC/DC0%0/4
$token_type == 96 or $token_type == 133 or $token_type == 132 or $token_type == 99
$token_type == 96
$token_type == 133
$token_type == 132
$token_type == 99
Truth table0%0/5
A or B or C or D
A= $token_type == 96B= $token_type == 133C= $token_type == 132D= $token_type == 99
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | $token_type == IF_STATEMENT || | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | $token_type == FOR_STATEMENT || | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | $token_type == WHILE_STATEMENT || | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | $token_type == UNLESS_STATEMENT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $is_in_ctrl_statement = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | elsif ($is_in_ctrl_statement) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ($token_type == LEFT_BRACE) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $left_brace_num++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | elsif ($token_type == RIGHT_BRACE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $left_brace_num--; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if ($left_brace_num <= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $is_in_ctrl_statement = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $is_in_map = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | elsif ($token_type == SEMI_COLON) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $is_in_context = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | $is_in_map = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | elsif ($token_type == COMMA) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $is_before_comma = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $is_before_comma = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | return \@violations; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||