line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::Variables::ProhibitAugmentedAssignmentInDeclaration; |
2
|
133
|
|
|
133
|
|
68201
|
use strict; |
|
133
|
|
|
|
|
168
|
|
|
133
|
|
|
|
|
3377
|
|
3
|
133
|
|
|
133
|
|
421
|
use warnings; |
|
133
|
|
|
|
|
147
|
|
|
133
|
|
|
|
|
2452
|
|
4
|
133
|
|
|
133
|
|
452
|
use Compiler::Lexer::Constants; |
|
133
|
|
|
|
|
165
|
|
|
133
|
|
|
|
|
2480
|
|
5
|
133
|
|
|
133
|
|
740
|
use parent "Perl::Lint::Policy"; |
|
133
|
|
|
|
|
387
|
|
|
133
|
|
|
|
|
474
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
8
|
133
|
|
|
|
|
35373
|
DESC => q{Augmented assignment operator '%s' used in declaration}, |
9
|
|
|
|
|
|
|
EXPL => q{Use simple assignment when initializing variables}, |
10
|
|
|
|
|
|
|
AUGMENTED_ASSIGNMENTS => { |
11
|
|
|
|
|
|
|
'**=' => 1, '+=' => 1, '-=' => 1, '.=' => 1, |
12
|
|
|
|
|
|
|
'*=' => 1, '/=' => 1, '%=' => 1, 'x=' => 1, |
13
|
|
|
|
|
|
|
'&=' => 1, '|=' => 1, '^=' => 1, '<<=' => 1, |
14
|
|
|
|
|
|
|
'>>=' => 1, '&&=' => 1, '||=' => 1, '//=' => 1, |
15
|
|
|
|
|
|
|
}, |
16
|
|
|
|
|
|
|
VAR => Compiler::Lexer::TokenType::T_Var, |
17
|
|
|
|
|
|
|
LOCAL_VAR => Compiler::Lexer::TokenType::T_LocalVar, |
18
|
|
|
|
|
|
|
GLOBAL_VAR => Compiler::Lexer::TokenType::T_GlobalVar, |
19
|
|
|
|
|
|
|
SEMI_COLON => Compiler::Lexer::TokenType::T_SemiColon, |
20
|
|
|
|
|
|
|
ASSIGN => Compiler::Lexer::TokenType::T_Assign, |
21
|
|
|
|
|
|
|
DECL => Compiler::Lexer::Kind::T_Decl, |
22
|
|
|
|
|
|
|
KIND_ASSIGN => Compiler::Lexer::Kind::T_Assign, |
23
|
133
|
|
|
133
|
|
12843
|
}; |
|
133
|
|
|
|
|
161
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub evaluate { |
26
|
6
|
|
|
6
|
0
|
10
|
my ($class, $file, $tokens) = @_; |
27
|
|
|
|
|
|
|
|
28
|
6
|
|
|
|
|
4
|
my @violations; |
29
|
6
|
|
|
|
|
7
|
my $token_num = scalar @$tokens; |
30
|
6
|
|
|
|
|
14
|
for (my $i = 0; $i < $token_num; $i++) { |
31
|
419
|
100
|
|
|
|
664
|
if ($tokens->[$i]->{kind} == DECL) { |
32
|
86
|
|
|
|
|
53
|
$i++; |
33
|
86
|
|
|
|
|
69
|
my $var_type = $tokens->[$i]->{type}; |
34
|
86
|
100
|
100
|
|
|
174
|
if ($var_type == VAR || $var_type == LOCAL_VAR || $var_type == GLOBAL_VAR) { |
|
|
|
100
|
|
|
|
|
35
|
82
|
|
|
|
|
98
|
for ($i++; $i < $token_num; $i++) { |
36
|
88
|
|
|
|
|
58
|
my $token = $tokens->[$i]; |
37
|
88
|
100
|
100
|
|
|
239
|
if ( |
|
|
100
|
66
|
|
|
|
|
38
|
|
|
|
|
|
|
$token->{kind} == KIND_ASSIGN && |
39
|
|
|
|
|
|
|
AUGMENTED_ASSIGNMENTS->{$token->{data}} # XXX Not good |
40
|
|
|
|
|
|
|
) { |
41
|
|
|
|
|
|
|
push @violations, { |
42
|
|
|
|
|
|
|
filename => $file, |
43
|
|
|
|
|
|
|
line => $token->{line}, |
44
|
73
|
|
|
|
|
241
|
description => sprintf(DESC, $token->{data}), |
45
|
|
|
|
|
|
|
explanation => EXPL, |
46
|
|
|
|
|
|
|
policy => __PACKAGE__, |
47
|
|
|
|
|
|
|
}; |
48
|
73
|
|
|
|
|
117
|
last; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
elsif ($token->{type} == ASSIGN || $token->{type} == SEMI_COLON) { |
51
|
9
|
|
|
|
|
15
|
last; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
6
|
|
|
|
|
22
|
return \@violations; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|