« Perl/Lint/Policy/Modules/RequireVersionVar.pm
↑ Summary
Perl/Lint/Policy/CodeLayout/ProhibitParensWithBuiltins.pm »
| 1 | package Perl::Lint::Policy::BuiltinFunctions::ProhibitVoidGrep; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 => '"grep" used in void context', | |||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | EXPL => 'Use a "for" loop instead', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub evaluate { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evaluate: not called CC=18 SCAR=58.3
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_in_grep = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | my $is_in_ctrl_statement = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | my $left_brace_num = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | for (my $i = 0; my $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | my $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my $token_data = $token->{data}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | if ($token_type == BUILTIN_FUNC) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | if ($token_data eq 'grep') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | next if $is_in_grep; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | if ($is_in_ctrl_statement) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | if ($left_brace_num) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | push @violations, { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | filename => $file, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | line => $token->{line}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | description => DESC, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | explanation => EXPL, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | policy => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | elsif (!$is_in_context) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | push @violations, { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | filename => $file, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | line => $token->{line}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | description => DESC, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | explanation => EXPL, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | policy => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $is_in_grep = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $is_in_context = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | elsif ($token_type == ASSIGN) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | $is_in_context = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | $token_type == IF_STATEMENT || | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | $token_type == FOR_STATEMENT || | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | $token_type == WHILE_STATEMENT || | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | $token_type == UNLESS_STATEMENT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $is_in_ctrl_statement = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | elsif ($is_in_ctrl_statement) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ($token_type == LEFT_BRACE) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $left_brace_num++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | elsif ($token_type == RIGHT_BRACE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $left_brace_num--; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if ($left_brace_num <= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $is_in_ctrl_statement = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $is_in_grep = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | elsif ($token_type == SEMI_COLON) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $is_in_context = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $is_in_grep = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | return \@violations; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||