line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::CodeLayout::RequireTrailingCommas; |
2
|
134
|
|
|
134
|
|
95562
|
use strict; |
|
134
|
|
|
|
|
340
|
|
|
134
|
|
|
|
|
4785
|
|
3
|
134
|
|
|
134
|
|
603
|
use warnings; |
|
134
|
|
|
|
|
219
|
|
|
134
|
|
|
|
|
3456
|
|
4
|
134
|
|
|
134
|
|
1234
|
use Perl::Lint::Constants::Type; |
|
134
|
|
|
|
|
206
|
|
|
134
|
|
|
|
|
83818
|
|
5
|
134
|
|
|
134
|
|
1648
|
use Perl::Lint::Constants::Kind; |
|
134
|
|
|
|
|
218
|
|
|
134
|
|
|
|
|
9897
|
|
6
|
134
|
|
|
134
|
|
866
|
use parent "Perl::Lint::Policy"; |
|
134
|
|
|
|
|
270
|
|
|
134
|
|
|
|
|
3116
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use constant { |
9
|
134
|
|
|
|
|
55501
|
DESC => 'List declaration without trailing comma', |
10
|
|
|
|
|
|
|
EXPL => [17], |
11
|
134
|
|
|
134
|
|
9219
|
}; |
|
134
|
|
|
|
|
420
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub evaluate { |
14
|
8
|
|
|
8
|
0
|
21
|
my ($class, $file, $tokens, $src, $args) = @_; |
15
|
|
|
|
|
|
|
|
16
|
8
|
|
|
|
|
14
|
my @violations; |
17
|
8
|
|
|
|
|
44
|
for (my $i = 0; my $token = $tokens->[$i]; $i++) { |
18
|
136
|
|
|
|
|
160
|
my $token_type = $token->{type}; |
19
|
|
|
|
|
|
|
|
20
|
136
|
100
|
|
|
|
350
|
if ($token_type == ASSIGN) { |
21
|
24
|
|
|
|
|
37
|
$token = $tokens->[++$i]; |
22
|
|
|
|
|
|
|
|
23
|
24
|
100
|
|
|
|
66
|
if ($token->{type} == LEFT_PAREN) { # TODO enough? |
24
|
22
|
|
|
|
|
31
|
my $begin_line = $token->{line}; |
25
|
|
|
|
|
|
|
|
26
|
22
|
|
|
|
|
26
|
my $left_paren_num = 1; |
27
|
22
|
|
|
|
|
23
|
my $num_of_item = 0; |
28
|
22
|
|
|
|
|
24
|
my $is_nested = 0; |
29
|
22
|
|
|
|
|
23
|
my $does_exist_procedure = 0; |
30
|
22
|
|
|
|
|
20
|
my $does_exist_any_comma = 0; |
31
|
|
|
|
|
|
|
|
32
|
22
|
|
|
|
|
69
|
for ($i++; $token = $tokens->[$i]; $i++) { |
33
|
138
|
|
|
|
|
160
|
$token_type = $token->{type}; |
34
|
|
|
|
|
|
|
|
35
|
138
|
100
|
|
|
|
454
|
if ($token_type == LEFT_PAREN) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
36
|
2
|
|
|
|
|
4
|
$left_paren_num++; |
37
|
2
|
|
|
|
|
6
|
$is_nested = 1; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_PAREN) { |
40
|
24
|
100
|
|
|
|
57
|
if (--$left_paren_num <= 0) { |
41
|
22
|
|
|
|
|
34
|
my $end_line = $token->{line}; |
42
|
22
|
100
|
100
|
|
|
218
|
if ( |
|
|
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
43
|
|
|
|
|
|
|
!$is_nested && |
44
|
|
|
|
|
|
|
(!$does_exist_procedure || $does_exist_any_comma) && |
45
|
|
|
|
|
|
|
$num_of_item > 1 && |
46
|
|
|
|
|
|
|
$end_line - $begin_line > 0 |
47
|
|
|
|
|
|
|
) { |
48
|
12
|
|
|
|
|
21
|
my $just_before_token = $tokens->[$i-1]; |
49
|
12
|
100
|
|
|
|
38
|
if ($just_before_token->{type} != COMMA) { |
50
|
9
|
|
|
|
|
69
|
push @violations, { |
51
|
|
|
|
|
|
|
filename => $file, |
52
|
|
|
|
|
|
|
line => $token->{line}, |
53
|
|
|
|
|
|
|
description => DESC, |
54
|
|
|
|
|
|
|
explanation => EXPL, |
55
|
|
|
|
|
|
|
policy => __PACKAGE__, |
56
|
|
|
|
|
|
|
}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
22
|
|
|
|
|
96
|
last; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
elsif ( |
64
|
|
|
|
|
|
|
$token->{kind} == KIND_OP |
65
|
|
|
|
|
|
|
) { |
66
|
9
|
|
|
|
|
23
|
$does_exist_procedure = 1; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
elsif ($token_type == COMMA) { |
69
|
34
|
|
|
|
|
80
|
$does_exist_any_comma = 1; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
else { |
72
|
69
|
|
|
|
|
156
|
$num_of_item++; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
8
|
|
|
|
|
56
|
return \@violations; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|