line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::RegularExpressions::ProhibitUnusualDelimiters; |
2
|
|
|
|
|
|
|
|
3
|
40
|
|
|
40
|
|
26998
|
use 5.010001; |
|
40
|
|
|
|
|
203
|
|
4
|
40
|
|
|
40
|
|
344
|
use strict; |
|
40
|
|
|
|
|
130
|
|
|
40
|
|
|
|
|
841
|
|
5
|
40
|
|
|
40
|
|
247
|
use warnings; |
|
40
|
|
|
|
|
126
|
|
|
40
|
|
|
|
|
1193
|
|
6
|
40
|
|
|
40
|
|
327
|
use Readonly; |
|
40
|
|
|
|
|
144
|
|
|
40
|
|
|
|
|
2281
|
|
7
|
|
|
|
|
|
|
|
8
|
40
|
|
|
40
|
|
365
|
use English qw(-no_match_vars); |
|
40
|
|
|
|
|
193
|
|
|
40
|
|
|
|
|
361
|
|
9
|
40
|
|
|
40
|
|
16466
|
use Carp; |
|
40
|
|
|
|
|
130
|
|
|
40
|
|
|
|
|
2668
|
|
10
|
|
|
|
|
|
|
|
11
|
40
|
|
|
40
|
|
317
|
use Perl::Critic::Utils qw{ :booleans :severities hashify }; |
|
40
|
|
|
|
|
184
|
|
|
40
|
|
|
|
|
2031
|
|
12
|
|
|
|
|
|
|
|
13
|
40
|
|
|
40
|
|
7316
|
use parent 'Perl::Critic::Policy'; |
|
40
|
|
|
|
|
178
|
|
|
40
|
|
|
|
|
267
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '1.148'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q<Use only '//' or '{}' to delimit regexps>; |
20
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => [246]; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Readonly::Array my @EXTRA_BRACKETS => qw{ () [] <> }; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub supported_parameters { |
27
|
|
|
|
|
|
|
return ( |
28
|
|
|
|
|
|
|
{ |
29
|
93
|
|
|
93
|
0
|
2426
|
name => 'allow_all_brackets', |
30
|
|
|
|
|
|
|
description => |
31
|
|
|
|
|
|
|
q[In addition to allowing '{}', allow '()', '[]', and '{}'.], |
32
|
|
|
|
|
|
|
behavior => 'boolean', |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
99
|
|
|
99
|
1
|
451
|
sub default_severity { return $SEVERITY_LOWEST } |
38
|
84
|
|
|
84
|
1
|
421
|
sub default_themes { return qw( core pbp cosmetic ) } |
39
|
33
|
|
|
33
|
1
|
126
|
sub applies_to { return qw(PPI::Token::Regexp::Match |
40
|
|
|
|
|
|
|
PPI::Token::Regexp::Substitute |
41
|
|
|
|
|
|
|
PPI::Token::QuoteLike::Regexp) } |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub initialize_if_enabled { |
46
|
50
|
|
|
50
|
1
|
225
|
my ( $self, $config ) = @_; |
47
|
|
|
|
|
|
|
|
48
|
50
|
|
|
|
|
253
|
my %delimiters = hashify( qw< // {} > ); |
49
|
50
|
100
|
|
|
|
302
|
if ( $self->{_allow_all_brackets} ) { |
50
|
1
|
|
|
|
|
8
|
@delimiters{ @EXTRA_BRACKETS } = (1) x @EXTRA_BRACKETS; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
50
|
|
|
|
|
217
|
$self->{_allowed_delimiters} = \%delimiters; |
54
|
|
|
|
|
|
|
|
55
|
50
|
|
|
|
|
237
|
return $TRUE; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub violates { |
61
|
51
|
|
|
51
|
1
|
105
|
my ( $self, $elem, undef ) = @_; |
62
|
|
|
|
|
|
|
|
63
|
51
|
|
|
|
|
94
|
my $allowed_delimiters = $self->{_allowed_delimiters}; |
64
|
51
|
|
|
|
|
148
|
foreach my $delimiter ($elem->get_delimiters()) { |
65
|
69
|
100
|
|
|
|
1027
|
next if $allowed_delimiters->{$delimiter}; |
66
|
25
|
|
|
|
|
89
|
return $self->violation( $DESC, $EXPL, $elem ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
26
|
|
|
|
|
64
|
return; # OK |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=pod |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 NAME |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Perl::Critic::Policy::RegularExpressions::ProhibitUnusualDelimiters - Use only C<//> or C<{}> to delimit regexps. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 AFFILIATION |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This Policy is part of the core L<Perl::Critic|Perl::Critic> |
88
|
|
|
|
|
|
|
distribution. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 DESCRIPTION |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Perl lets you delimit regular expressions with almost any character, |
94
|
|
|
|
|
|
|
but most choices are illegible. Compare these equivalent expressions: |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
s/foo/bar/; # good |
97
|
|
|
|
|
|
|
s{foo}{bar}; # good |
98
|
|
|
|
|
|
|
s#foo#bar#; # bad |
99
|
|
|
|
|
|
|
s;foo;bar;; # worse |
100
|
|
|
|
|
|
|
s|\|\||\||; # eye-gouging bad |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 CONFIGURATION |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
There is one option for this policy, C<allow_all_brackets>. If this |
106
|
|
|
|
|
|
|
is true, then, in addition to allowing C<//> and C<{}>, the other |
107
|
|
|
|
|
|
|
matched pairs of C<()>, C<[]>, and C<< <> >> are allowed. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 CREDITS |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Initial development of this policy was supported by a grant from the |
113
|
|
|
|
|
|
|
Perl Foundation. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 AUTHOR |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Chris Dolan <cdolan@cpan.org> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 COPYRIGHT |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Copyright (c) 2007-2011 Chris Dolan. Many rights reserved. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
126
|
|
|
|
|
|
|
it under the same terms as Perl itself. The full text of this license |
127
|
|
|
|
|
|
|
can be found in the LICENSE file included with this module |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# Local Variables: |
132
|
|
|
|
|
|
|
# mode: cperl |
133
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
134
|
|
|
|
|
|
|
# fill-column: 78 |
135
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
136
|
|
|
|
|
|
|
# c-indentation-style: bsd |
137
|
|
|
|
|
|
|
# End: |
138
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |