| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Module::Checkstyle::Check::Whitespace; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
8479
|
use strict; |
|
|
2
|
|
|
|
|
7
|
|
|
|
2
|
|
|
|
|
214
|
|
|
4
|
2
|
|
|
2
|
|
18
|
use warnings; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
92
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
10
|
use Carp qw(croak); |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
165
|
|
|
7
|
2
|
|
|
2
|
|
2452
|
use Readonly; |
|
|
2
|
|
|
|
|
7371
|
|
|
|
2
|
|
|
|
|
166
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
782
|
use Module::Checkstyle::Util qw(:problem :args); |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
446
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
15
|
use base qw(Module::Checkstyle::Check); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
2063
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# The directives we provide |
|
14
|
|
|
|
|
|
|
Readonly my $AFTER_COMMA => 'after-comma'; |
|
15
|
|
|
|
|
|
|
Readonly my $BEFORE_COMMA => 'before-comma'; |
|
16
|
|
|
|
|
|
|
Readonly my $AFTER_FAT_COMMA => 'after-fat-comma'; |
|
17
|
|
|
|
|
|
|
Readonly my $BEFORE_FAT_COMMA => 'before-fat-comma'; |
|
18
|
|
|
|
|
|
|
Readonly my $AFTER_COMPOUND => 'after-compound'; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub register { |
|
21
|
|
|
|
|
|
|
return ( |
|
22
|
0
|
|
|
0
|
1
|
0
|
'PPI::Token::Operator' => \&handle_operator, |
|
23
|
|
|
|
|
|
|
'PPI::Statement::Compound' => \&handle_compound, |
|
24
|
|
|
|
|
|
|
); |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new { |
|
28
|
4
|
|
|
4
|
1
|
11
|
my ($class, $config) = @_; |
|
29
|
|
|
|
|
|
|
|
|
30
|
4
|
|
|
|
|
27
|
my $self = $class->SUPER::new($config); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Keep configuration local |
|
33
|
4
|
|
|
|
|
9
|
foreach ($AFTER_COMMA, $BEFORE_COMMA, $AFTER_FAT_COMMA, $BEFORE_FAT_COMMA, $AFTER_COMPOUND) { |
|
34
|
20
|
|
|
|
|
127
|
$self->{$_} = as_true($config->get_directive($_)); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
4
|
|
|
|
|
31
|
return $self; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub handle_operator { |
|
41
|
24
|
|
|
24
|
1
|
52056
|
my ($self, $operator, $file) = @_; |
|
42
|
|
|
|
|
|
|
|
|
43
|
24
|
|
|
|
|
32
|
my @problems; |
|
44
|
|
|
|
|
|
|
|
|
45
|
24
|
|
|
|
|
68
|
push @problems, $self->_handle_comma($operator, $file); |
|
46
|
24
|
|
|
|
|
56
|
push @problems, $self->_handle_fat_comma($operator, $file); |
|
47
|
|
|
|
|
|
|
|
|
48
|
24
|
|
|
|
|
65
|
return @problems; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _handle_comma { |
|
52
|
24
|
|
|
24
|
|
34
|
my ($self, $operator, $file) = @_; |
|
53
|
|
|
|
|
|
|
|
|
54
|
24
|
|
|
|
|
25
|
my @problems; |
|
55
|
|
|
|
|
|
|
|
|
56
|
24
|
100
|
|
|
|
82
|
if ($operator->content() eq ',') { |
|
57
|
16
|
100
|
|
|
|
327
|
if ($self->{$AFTER_COMMA}) { |
|
58
|
|
|
|
|
|
|
# Next sibling should be whitespace |
|
59
|
8
|
|
|
|
|
249
|
my $sibling = $operator->next_sibling(); |
|
60
|
8
|
100
|
33
|
|
|
1369
|
if ($sibling && ref $sibling && !$sibling->isa('PPI::Token::Whitespace')) { |
|
|
|
|
66
|
|
|
|
|
|
61
|
4
|
|
|
|
|
26
|
push @problems, new_problem($self->config, $AFTER_COMMA, |
|
62
|
|
|
|
|
|
|
qq(Missing whitespace after comma (,)), |
|
63
|
|
|
|
|
|
|
$operator, $file); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
16
|
100
|
|
|
|
100
|
if ($self->{$BEFORE_COMMA}) { |
|
68
|
|
|
|
|
|
|
# Previous sibling should be whitespace |
|
69
|
8
|
|
|
|
|
69
|
my $sibling = $operator->previous_sibling(); |
|
70
|
8
|
100
|
33
|
|
|
274
|
if ($sibling && ref $sibling && !$sibling->isa('PPI::Token::Whitespace')) { |
|
|
|
|
66
|
|
|
|
|
|
71
|
4
|
|
|
|
|
24
|
push @problems, new_problem($self->config, $BEFORE_COMMA, |
|
72
|
|
|
|
|
|
|
qq(Missing whitespace before comma (,)), |
|
73
|
|
|
|
|
|
|
$operator, $file); |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
24
|
|
|
|
|
289
|
return @problems; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _handle_fat_comma { |
|
82
|
24
|
|
|
24
|
|
201
|
my ($self, $operator, $file) = @_; |
|
83
|
|
|
|
|
|
|
|
|
84
|
24
|
|
|
|
|
29
|
my @problems; |
|
85
|
|
|
|
|
|
|
|
|
86
|
24
|
100
|
|
|
|
64
|
if ($operator->content() eq '=>') { |
|
87
|
8
|
50
|
|
|
|
58
|
if ($self->{$AFTER_FAT_COMMA}) { |
|
88
|
|
|
|
|
|
|
# Next sibling should be whitespace |
|
89
|
8
|
|
|
|
|
55
|
my $sibling = $operator->next_sibling(); |
|
90
|
8
|
100
|
33
|
|
|
245
|
if ($sibling && ref $sibling && !$sibling->isa('PPI::Token::Whitespace')) { |
|
|
|
|
66
|
|
|
|
|
|
91
|
4
|
|
|
|
|
14
|
push @problems, new_problem($self->config, $AFTER_FAT_COMMA, |
|
92
|
|
|
|
|
|
|
qq(Missing whitespace after fat comma (=>)), |
|
93
|
|
|
|
|
|
|
$operator, $file); |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
8
|
50
|
|
|
|
27
|
if ($self->{$BEFORE_FAT_COMMA}) { |
|
98
|
|
|
|
|
|
|
# Previous sibling should be whitespace |
|
99
|
0
|
|
|
|
|
0
|
my $sibling = $operator->previous_sibling(); |
|
100
|
0
|
0
|
0
|
|
|
0
|
if ($sibling && ref $sibling && !$sibling->isa('PPI::Token::Whitespace')) { |
|
|
|
|
0
|
|
|
|
|
|
101
|
0
|
|
|
|
|
0
|
push @problems, new_problem($self->config, $BEFORE_FAT_COMMA, |
|
102
|
|
|
|
|
|
|
qq(Missing whitespace before fat comma (=>)), |
|
103
|
|
|
|
|
|
|
$operator, $file); |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
24
|
|
|
|
|
146
|
return @problems; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub handle_compound { |
|
112
|
3
|
|
|
3
|
1
|
10993
|
my ($self, $compound, $file) = @_; |
|
113
|
|
|
|
|
|
|
|
|
114
|
3
|
|
|
|
|
6
|
my @problems; |
|
115
|
|
|
|
|
|
|
|
|
116
|
3
|
50
|
|
|
|
13
|
if ($self->{$AFTER_COMPOUND}) { |
|
117
|
3
|
|
|
|
|
26
|
my @children = $compound->schildren(); |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
CHECK_COMPOUND_BLOCK: |
|
120
|
3
|
|
|
|
|
43
|
foreach my $child (@children) { |
|
121
|
14
|
100
|
|
|
|
65
|
next CHECK_COMPOUND_BLOCK if !$child->isa('PPI::Token::Word'); |
|
122
|
5
|
|
|
|
|
12
|
my $word = $child->content(); |
|
123
|
5
|
|
|
|
|
32
|
my $sibling = $child->next_sibling(); |
|
124
|
5
|
100
|
33
|
|
|
135
|
if (defined $sibling && ref $sibling && !$sibling->isa('PPI::Token::Whitespace')) { |
|
|
|
|
66
|
|
|
|
|
|
125
|
3
|
|
|
|
|
10
|
push @problems, new_problem($self->config, $AFTER_COMPOUND, |
|
126
|
|
|
|
|
|
|
qq('$word' is not followed by whitespace), |
|
127
|
|
|
|
|
|
|
$child, $file); |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
3
|
|
|
|
|
11
|
return @problems; |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
1; |
|
136
|
|
|
|
|
|
|
__END__ |