| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::Subroutines::ProhibitManyArgs; |
|
2
|
133
|
|
|
133
|
|
69269
|
use strict; |
|
|
133
|
|
|
|
|
193
|
|
|
|
133
|
|
|
|
|
3264
|
|
|
3
|
133
|
|
|
133
|
|
421
|
use warnings; |
|
|
133
|
|
|
|
|
172
|
|
|
|
133
|
|
|
|
|
2545
|
|
|
4
|
133
|
|
|
133
|
|
783
|
use Perl::Lint::Constants::Type; |
|
|
133
|
|
|
|
|
167
|
|
|
|
133
|
|
|
|
|
60061
|
|
|
5
|
133
|
|
|
133
|
|
612
|
use parent "Perl::Lint::Policy"; |
|
|
133
|
|
|
|
|
174
|
|
|
|
133
|
|
|
|
|
606
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
|
8
|
133
|
|
|
|
|
50038
|
DESC => 'Too many arguments', |
|
9
|
|
|
|
|
|
|
EXPL => [182], |
|
10
|
133
|
|
|
133
|
|
7005
|
}; |
|
|
133
|
|
|
|
|
219
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub evaluate { |
|
13
|
9
|
|
|
9
|
0
|
13
|
my ($class, $file, $tokens, $src, $args) = @_; |
|
14
|
|
|
|
|
|
|
|
|
15
|
9
|
|
100
|
|
|
29
|
my $max_arguments = $args->{prohibit_many_args}->{max_arguments} || 5; |
|
16
|
|
|
|
|
|
|
|
|
17
|
9
|
|
|
|
|
7
|
my @violations; |
|
18
|
9
|
|
|
|
|
21
|
for (my $i = 0; my $token = $tokens->[$i]; $i++) { |
|
19
|
47
|
|
|
|
|
33
|
my $token_type = $token->{type}; |
|
20
|
|
|
|
|
|
|
|
|
21
|
47
|
100
|
|
|
|
82
|
if ($token_type == FUNCTION_DECL) { |
|
22
|
9
|
|
|
|
|
17
|
for ($i++; $token = $tokens->[$i]; $i++) { |
|
23
|
82
|
|
|
|
|
53
|
$token_type = $token->{type}; |
|
24
|
82
|
100
|
|
|
|
157
|
if ($token_type == LEFT_BRACE) { |
|
|
|
100
|
|
|
|
|
|
|
25
|
17
|
|
|
|
|
13
|
my $left_brace_num = 1; |
|
26
|
17
|
|
|
|
|
13
|
my $num_of_vars = 0; |
|
27
|
17
|
|
|
|
|
9
|
my $num_of_vars_per_one_line = 0; |
|
28
|
17
|
|
|
|
|
11
|
my $last_var_token; |
|
29
|
17
|
|
|
|
|
27
|
for ($i++; $token = $tokens->[$i]; $i++) { |
|
30
|
215
|
|
|
|
|
128
|
$token_type = $token->{type}; |
|
31
|
|
|
|
|
|
|
|
|
32
|
215
|
50
|
66
|
|
|
2058
|
if ($token_type == LEFT_BRACE) { |
|
|
|
100
|
100
|
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
|
100
|
33
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
33
|
0
|
|
|
|
|
0
|
$left_brace_num++; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_BRACE) { |
|
36
|
17
|
50
|
|
|
|
23
|
if (--$left_brace_num <= 0) { |
|
37
|
17
|
100
|
|
|
|
20
|
if ($num_of_vars > $max_arguments) { |
|
38
|
|
|
|
|
|
|
push @violations, { |
|
39
|
|
|
|
|
|
|
filename => $file, |
|
40
|
|
|
|
|
|
|
line => $last_var_token->{line}, |
|
41
|
6
|
|
|
|
|
25
|
description => DESC, |
|
42
|
|
|
|
|
|
|
explanation => EXPL, |
|
43
|
|
|
|
|
|
|
policy => __PACKAGE__, |
|
44
|
|
|
|
|
|
|
}; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
17
|
|
|
|
|
51
|
last; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
elsif ( |
|
50
|
|
|
|
|
|
|
$token_type == VAR || |
|
51
|
|
|
|
|
|
|
$token_type == LOCAL_VAR || |
|
52
|
|
|
|
|
|
|
$token_type == GLOBAL_VAR || |
|
53
|
|
|
|
|
|
|
$token_type == ARRAY_VAR || |
|
54
|
|
|
|
|
|
|
$token_type == LOCAL_ARRAY_VAR || |
|
55
|
|
|
|
|
|
|
$token_type == GLOBAL_ARRAY_VAR || |
|
56
|
|
|
|
|
|
|
$token_type == HASH_VAR || |
|
57
|
|
|
|
|
|
|
$token_type == LOCAL_HASH_VAR || |
|
58
|
|
|
|
|
|
|
$token_type == GLOBAL_HASH_VAR |
|
59
|
|
|
|
|
|
|
) { |
|
60
|
42
|
50
|
|
|
|
44
|
if ($left_brace_num == 1) { # XXX |
|
61
|
42
|
|
|
|
|
57
|
$num_of_vars_per_one_line++; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
elsif ($token_type == ASSIGN) { |
|
65
|
26
|
|
|
|
|
22
|
my $next_token = $tokens->[$i+1]; |
|
66
|
26
|
|
|
|
|
18
|
my $next_token_type = $next_token->{type}; |
|
67
|
26
|
|
|
|
|
21
|
my $next_token_data = $next_token->{data}; |
|
68
|
|
|
|
|
|
|
|
|
69
|
26
|
50
|
33
|
|
|
79
|
if ( |
|
|
|
|
66
|
|
|
|
|
|
70
|
|
|
|
|
|
|
$next_token_type == ARGUMENT_ARRAY || |
|
71
|
|
|
|
|
|
|
($next_token_type == BUILTIN_FUNC && $next_token_data eq 'shift') |
|
72
|
|
|
|
|
|
|
) { |
|
73
|
26
|
|
|
|
|
19
|
$num_of_vars += $num_of_vars_per_one_line; |
|
74
|
26
|
|
|
|
|
38
|
$last_var_token = $token; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
elsif ($token_type == SEMI_COLON) { |
|
78
|
30
|
|
|
|
|
41
|
$num_of_vars_per_one_line = 0; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
elsif ($token_type == PROTOTYPE) { |
|
83
|
11
|
|
|
|
|
24
|
(my $prototype = $token->{data}) =~ s/[ ;]//g; |
|
84
|
11
|
|
|
|
|
17
|
$prototype =~ s/\\\[.+?\]/1/g; # XXX |
|
85
|
11
|
100
|
|
|
|
22
|
if (length $prototype > $max_arguments) { |
|
86
|
|
|
|
|
|
|
push @violations, { |
|
87
|
|
|
|
|
|
|
filename => $file, |
|
88
|
|
|
|
|
|
|
line => $token->{line}, |
|
89
|
4
|
|
|
|
|
15
|
description => DESC, |
|
90
|
|
|
|
|
|
|
explanation => EXPL, |
|
91
|
|
|
|
|
|
|
policy => __PACKAGE__, |
|
92
|
|
|
|
|
|
|
}; |
|
93
|
4
|
|
|
|
|
9
|
last; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
9
|
|
|
|
|
29
|
return \@violations; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
|
104
|
|
|
|
|
|
|
|