« Perl/Lint/Policy/Variables/ProhibitReusedNames.pm
↑ Summary
Perl/Lint/Policy/TestingAndDebugging/ProhibitProlongedStrictureOverride.pm »
| 1 | package Perl::Lint::Policy::Subroutines::ProhibitReturnSort; | ||||||||||||||||||||||||||||||||||||||||||
| 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 => '"return" statement followed by "sort"', | |||||||||||||||||||||||||||||||||||||||||
| 9 | EXPL => 'Behavior is undefined if called in scalar context', | ||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | sub evaluate { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evaluate: not called CC=23 SCAR=63.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | my ($class, $file, $tokens, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | my @violations; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | for (my $i = 0; my $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | my $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | if ($token_type == RETURN) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | my $next_token = $tokens->[$i+1]; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | if ($next_token->{type} == BUILTIN_FUNC && $next_token->{data} eq 'sort') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$next_token->{"type"} == 70 and $next_token->{"data"} eq "sort"
MC/DC0%0/2
$next_token->{"type"} == 70 and $next_token->{"data"} eq "sort"
$next_token->{"type"} == 70
$next_token->{"data"} eq "sort"
Truth table0%0/3
A and B
A= $next_token->{"type"} == 70B= $next_token->{"data"} eq "sort"
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | my $is_in_postposition_if = 0; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | my $is_wantarray = 0; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | for ($i++; my $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | if ($token_type == SEMI_COLON) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | if (!$is_wantarray) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | push @violations, { | ||||||||||||||||||||||||||||||||||||||||||
| 29 | filename => $file, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | line => $token->{line}, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | description => DESC, | |||||||||||||||||||||||||||||||||||||||||
| 32 | explanation => EXPL, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | policy => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | elsif ($token_type == IF_STATEMENT) { | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $is_in_postposition_if = 1; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | ▶ | elsif ($token_type == BUILTIN_FUNC && $token->{data} eq 'wantarray' && $is_in_postposition_if) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$token_type == 70 and $token->{"data"} eq "wantarray" and $is_in_postposition_if
$token_type == 70 and $token->{"data"} eq "wantarray"
MC/DC0%0/3
$token_type == 70 and $token->{"data"} eq "wantarray" and $is_in_postposition_if
$token_type == 70
$token->{"data"} eq "wantarray"
$is_in_postposition_if
Truth table0%0/4
A and B and C
A= $token_type == 70B= $token->{"data"} eq "wantarray"C= $is_in_postposition_if
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $is_wantarray = 1; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | elsif ($token_type == IF_STATEMENT) { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my $left_brace_num = 0; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my $is_wantarray = 0; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | for ($i++; my $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ($token_type == LEFT_BRACE) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $left_brace_num++; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | elsif ($token_type == RIGHT_BRACE) { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | $left_brace_num--; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | last if ($left_brace_num <= 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | ▶ | elsif ($token_type == BUILTIN_FUNC && $token->{data} eq 'wantarray') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$token_type == 70 and $token->{"data"} eq "wantarray"
MC/DC0%0/2
$token_type == 70 and $token->{"data"} eq "wantarray"
$token_type == 70
$token->{"data"} eq "wantarray"
Truth table0%0/3
A and B
A= $token_type == 70B= $token->{"data"} eq "wantarray"
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $is_wantarray = 1; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | elsif (!$is_wantarray) { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $next_token = $tokens->[$i+1]; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ($next_token && $next_token->{type} == BUILTIN_FUNC && $next_token->{data} eq 'sort') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$next_token and $next_token->{"type"} == 70 and $next_token->{"data"} eq "sort"
$next_token and $next_token->{"type"} == 70
MC/DC0%0/3
$next_token and $next_token->{"type"} == 70 and $next_token->{"data"} eq "sort"
$next_token
$next_token->{"type"} == 70
$next_token->{"data"} eq "sort"
Truth table0%0/4
A and B and C
A= $next_tokenB= $next_token->{"type"} == 70C= $next_token->{"data"} eq "sort"
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | push @violations, { | ||||||||||||||||||||||||||||||||||||||||||
| 67 | filename => $file, | ||||||||||||||||||||||||||||||||||||||||||
| 68 | line => $token->{line}, | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | description => DESC, | |||||||||||||||||||||||||||||||||||||||||
| 70 | explanation => EXPL, | ||||||||||||||||||||||||||||||||||||||||||
| 71 | policy => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | return \@violations; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||