« Perl/Lint/Policy/Variables/ProhibitPunctuationVars.pm
↑ Summary
Perl/Lint/Policy/Variables/ProhibitEvilVariables.pm »
| 1 | package Perl::Lint::Policy::ValuesAndExpressions::ProhibitLeadingZeros; | ||||||||||||||||||||||||||||||||
| 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 => q{Don't allow any leading zeros at all. Otherwise builtins that deal with Unix permissions, e.g. chmod, don't get flagged.}, | |||||||||||||||||||||||||||||||
| 9 | EXPL => [58], | ||||||||||||||||||||||||||||||||
| 10 | 2 | }; | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | sub evaluate { | ||||||||||||||||||||||||||||||
|
Subroutine
evaluate: not called CC=33 SCAR=70.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 13 | 0 | my ($class, $file, $tokens, $src, $args) = @_; | |||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 0 | my $is_strict; | |||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | if (my $this_policies_arg = $args->{prohibit_leading_zeros}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 17 | 0 | $is_strict = $this_policies_arg->{strict}; | |||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 0 | my @violations; | |||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | for (my $i = 0; my $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 22 | 0 | my $token_type = $token->{type}; | |||||||||||||||||||||||||||||||
| 23 | 0 | my $token_data = $token->{data}; | |||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | if (!$is_strict && $token_type == BUILTIN_FUNC) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $is_strict and $token_type == 70
MC/DC0%0/2
not $is_strict and $token_type == 70
not $is_strict
$token_type == 70
Truth table0%0/3
not(A) and B
A= not $is_strictB= $token_type == 70
| |||||||||||||||||||||||||||||||||
| 26 | # skip the first argument of chmod() | ||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | if ($token_data eq 'chmod') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | if ($tokens->[++$i]->{type} == LEFT_PAREN) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 29 | 0 | $i++; | |||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||
| 31 | 0 | next; | |||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | # skip third argument of dbmopen() | ||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | if ($token_data eq 'dbmopen') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if ($tokens->[++$i]->{type} == LEFT_PAREN) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 37 | 0 | $i++; | |||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | 0 | my $comma_num = 0; | |||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | for ($i++; $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 42 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if ($token_type == SEMI_COLON) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 45 | 0 | last; | |||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ($token_type == COMMA) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 49 | 0 | $comma_num++; | |||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if ($comma_num == 2) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 53 | 0 | $i++; | |||||||||||||||||||||||||||||||
| 54 | 0 | last; | |||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||
| 57 | 0 | next; | |||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | # skip second argument of mkdir() | ||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ($token_data eq 'mkdir') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ($tokens->[++$i]->{type} == LEFT_PAREN) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 63 | 0 | $i++; | |||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | 0 | my $comma_num = 0; | |||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | for ($i++; $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 68 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ($token_type == SEMI_COLON) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 71 | 0 | last; | |||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ($token_type == COMMA) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 75 | 0 | $comma_num++; | |||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ($comma_num == 1) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 79 | 0 | $i++; | |||||||||||||||||||||||||||||||
| 80 | 0 | last; | |||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||
| 83 | 0 | next; | |||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | # skip the first argument of umask() | ||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if ($token_data eq 'umask') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | if ($tokens->[++$i]->{type} == LEFT_PAREN) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 89 | 0 | $i++; | |||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||
| 91 | 0 | next; | |||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if (!$is_strict && $token_type == KEY) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $is_strict and $token_type == 122
MC/DC0%0/2
not $is_strict and $token_type == 122
not $is_strict
$token_type == 122
Truth table0%0/3
not(A) and B
A= not $is_strictB= $token_type == 122
| |||||||||||||||||||||||||||||||||
| 96 | # skip the fourth argument of sysopen() | ||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if ($token_data eq 'sysopen') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if ($tokens->[++$i]->{type} == LEFT_PAREN) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 99 | 0 | $i++; | |||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | 0 | my $comma_num = 0; | |||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | for ($i++; $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 104 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if ($token_type == SEMI_COLON) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 107 | 0 | last; | |||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if ($token_type == COMMA) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 111 | 0 | $comma_num++; | |||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | if ($comma_num == 3) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 115 | 0 | $i++; | |||||||||||||||||||||||||||||||
| 116 | 0 | last; | |||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||
| 119 | 0 | next; | |||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if ($token_type == INT) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 124 | 0 | my $int = $token_data; | |||||||||||||||||||||||||||||||
| 125 | 0 | $int =~ s/_//g; | |||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if ($int =~ /\A-?0/ && (eval($int) // 0) != 0) { ## no critic: to accept bin, oct and hex decimal | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$int =~ /\A-?0/ and (eval $int // 0) != 0
eval $int // 0
MC/DC0%0/2
$int =~ /\A-?0/ and (eval $int // 0) != 0
$int =~ /\A-?0/
eval $int
Truth table0%0/3
A and B
A= $int =~ /\A-?0/B= eval $int
| |||||||||||||||||||||||||||||||||
| 127 | push @violations, { | ||||||||||||||||||||||||||||||||
| 128 | filename => $file, | ||||||||||||||||||||||||||||||||
| 129 | line => $token->{line}, | ||||||||||||||||||||||||||||||||
| 130 | 0 | description => DESC, | |||||||||||||||||||||||||||||||
| 131 | explanation => EXPL, | ||||||||||||||||||||||||||||||||
| 132 | policy => __PACKAGE__, | ||||||||||||||||||||||||||||||||
| 133 | }; | ||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||
| 135 | 0 | next; | |||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | 0 | return \@violations; | |||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | 2 | 1; | |||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||