« Perl/Lint/Policy/ValuesAndExpressions/ProhibitQuotesAsQuotelikeOperatorDelimiters.pm
↑ Summary
Perl/Lint/Policy/InputOutput/RequireEncodingWithUTF8Layer.pm »
| 1 | package Perl::Lint::Policy::BuiltinFunctions::ProhibitBooleanGrep; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 3 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | DESC => '"grep" used in boolean context', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | EXPL => [71, 72], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | sub evaluate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evaluate: called CC=29 SCAR=55.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | my ($class, $file, $tokens, $src, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | my @violations; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | my $is_grep_called = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | my $is_in_boolean_context = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | my $is_in_numeric_comparison_context = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | for (my $i = 0; my $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 51 | my $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 51 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$token_type == 96 or $token_type == 99 or $token_type == 132 or $token_type == 100
$token_type == 96 or $token_type == 99 or $token_type == 132
$token_type == 96 or $token_type == 99
MC/DC0%0/4
$token_type == 96 or $token_type == 99 or $token_type == 132 or $token_type == 100
$token_type == 96
$token_type == 99
$token_type == 132
$token_type == 100
Truth table20%1/5
A or B or C or D
A= $token_type == 96B= $token_type == 99C= $token_type == 132D= $token_type == 100
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | $token_type == IF_STATEMENT || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | $token_type == UNLESS_STATEMENT || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | $token_type == WHILE_STATEMENT || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | $token_type == UNTIL_STATEMENT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | $token = $tokens->[++$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | if ($token_type == LEFT_PAREN) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | my $is_grep_called = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my $is_in_numeric_comparison_context = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my $left_paren_num = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | for ($i++; $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ($token_type == EQUAL_EQUAL) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | $is_in_numeric_comparison_context = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | elsif ($token_type == LEFT_PAREN) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $left_paren_num++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | elsif ($token_type == RIGHT_PAREN) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if (--$left_paren_num <= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if ($is_grep_called && !$is_in_numeric_comparison_context) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$is_grep_called and not $is_in_numeric_comparison_context
MC/DC0%0/2
$is_grep_called and not $is_in_numeric_comparison_context
$is_grep_called
not $is_in_numeric_comparison_context
Truth table0%0/3
A and not(B)
A= $is_grep_calledB= not $is_in_numeric_comparison_context
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | push @violations, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | filename => $file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | line => $token->{line}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | description => DESC, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | explanation => EXPL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | policy => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | ▶ | elsif ($token_type == BUILTIN_FUNC && $token->{data} eq 'grep') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$token_type == 70 and $token->{"data"} eq "grep"
MC/DC0%0/2
$token_type == 70 and $token->{"data"} eq "grep"
$token_type == 70
$token->{"data"} eq "grep"
Truth table0%0/3
A and B
A= $token_type == 70B= $token->{"data"} eq "grep"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | $is_grep_called = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ▶ | elsif ($token_type == BUILTIN_FUNC && $token->{data} eq 'grep') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$token_type == 70 and $token->{"data"} eq "grep"
MC/DC0%0/2
$token_type == 70 and $token->{"data"} eq "grep"
$token_type == 70
$token->{"data"} eq "grep"
Truth table0%0/3
A and B
A= $token_type == 70B= $token->{"data"} eq "grep"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | push @violations, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | filename => $file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | line => $token->{line}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | description => DESC, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | explanation => EXPL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | policy => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 51 | ▶ | if ($token_type == BUILTIN_FUNC && $token->{data} eq 'grep') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$token_type == 70 and $token->{"data"} eq "grep"
MC/DC0%0/2
$token_type == 70 and $token->{"data"} eq "grep"
$token_type == 70
$token->{"data"} eq "grep"
Truth table66%2/3
A and B
A= $token_type == 70B= $token->{"data"} eq "grep"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | $is_grep_called = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 51 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$token_type == 53 or $token_type == 52 or $token_type == 14 or $token_type == 16
$token_type == 53 or $token_type == 52 or $token_type == 14
$token_type == 53 or $token_type == 52
MC/DC0%0/4
$token_type == 53 or $token_type == 52 or $token_type == 14 or $token_type == 16
$token_type == 53
$token_type == 52
$token_type == 14
$token_type == 16
Truth table20%1/5
A or B or C or D
A= $token_type == 53B= $token_type == 52C= $token_type == 14D= $token_type == 16
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | $token_type == OR || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | $token_type == AND || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | $token_type == ALPHABET_OR || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | $token_type == ALPHABET_AND | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $is_in_boolean_context = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 51 | ▶ | if ($token_type == EQUAL_EQUAL) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $is_in_numeric_comparison_context = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 51 | ▶ | if ($token_type == SEMI_COLON) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 11 | ▶ | if ($is_grep_called && $is_in_boolean_context && !$is_in_numeric_comparison_context) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$is_grep_called and $is_in_boolean_context and not $is_in_numeric_comparison_context
$is_grep_called and $is_in_boolean_context
MC/DC0%0/3
$is_grep_called and $is_in_boolean_context and not $is_in_numeric_comparison_context
$is_grep_called
$is_in_boolean_context
not $is_in_numeric_comparison_context
Truth table25%1/4
A and B and not(C)
A= $is_grep_calledB= $is_in_boolean_contextC= not $is_in_numeric_comparison_context
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | push @violations, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | filename => $file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | line => $token->{line}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | description => DESC, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | explanation => EXPL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | policy => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 11 | $is_grep_called = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 11 | $is_in_boolean_context = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 11 | $is_in_numeric_comparison_context = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 11 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 2 | return \@violations; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||