line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::TestingAndDebugging::ProhibitNoStrict; |
2
|
|
|
|
|
|
|
|
3
|
40
|
|
|
40
|
|
28577
|
use 5.010001; |
|
40
|
|
|
|
|
184
|
|
4
|
40
|
|
|
40
|
|
260
|
use strict; |
|
40
|
|
|
|
|
161
|
|
|
40
|
|
|
|
|
876
|
|
5
|
40
|
|
|
40
|
|
207
|
use warnings; |
|
40
|
|
|
|
|
98
|
|
|
40
|
|
|
|
|
933
|
|
6
|
40
|
|
|
40
|
|
215
|
use Readonly; |
|
40
|
|
|
|
|
116
|
|
|
40
|
|
|
|
|
2050
|
|
7
|
|
|
|
|
|
|
|
8
|
40
|
|
|
40
|
|
256
|
use List::SomeUtils qw(all); |
|
40
|
|
|
|
|
122
|
|
|
40
|
|
|
|
|
1831
|
|
9
|
|
|
|
|
|
|
|
10
|
40
|
|
|
40
|
|
255
|
use Perl::Critic::Utils qw{ :characters :severities :data_conversion }; |
|
40
|
|
|
|
|
121
|
|
|
40
|
|
|
|
|
2011
|
|
11
|
40
|
|
|
40
|
|
12673
|
use parent 'Perl::Critic::Policy'; |
|
40
|
|
|
|
|
130
|
|
|
40
|
|
|
|
|
231
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '1.146'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{Stricture disabled}; |
18
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => [ 429 ]; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub supported_parameters { |
23
|
|
|
|
|
|
|
return ( |
24
|
|
|
|
|
|
|
{ |
25
|
100
|
|
|
100
|
0
|
2202
|
name => 'allow', |
26
|
|
|
|
|
|
|
description => 'Allow vars, subs, and/or refs.', |
27
|
|
|
|
|
|
|
default_string => $EMPTY, |
28
|
|
|
|
|
|
|
parser => \&_parse_allow, |
29
|
|
|
|
|
|
|
}, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
80
|
|
|
80
|
1
|
385
|
sub default_severity { return $SEVERITY_HIGHEST } |
34
|
92
|
|
|
92
|
1
|
448
|
sub default_themes { return qw( core pbp bugs certrec ) } |
35
|
46
|
|
|
46
|
1
|
158
|
sub applies_to { return 'PPI::Statement::Include' } |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _parse_allow { |
40
|
98
|
|
|
98
|
|
536
|
my ($self, $parameter, $config_string) = @_; |
41
|
|
|
|
|
|
|
|
42
|
98
|
|
|
|
|
469
|
$self->{_allow} = {}; |
43
|
|
|
|
|
|
|
|
44
|
98
|
100
|
|
|
|
497
|
if( defined $config_string ) { |
45
|
9
|
|
|
|
|
34
|
my $allowed = lc $config_string; #String of words |
46
|
9
|
|
|
|
|
69
|
my %allowed = hashify( $allowed =~ m/ (\w+) /gxms ); |
47
|
9
|
|
|
|
|
36
|
$self->{_allow} = \%allowed; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
98
|
|
|
|
|
289
|
return; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub violates { |
56
|
73
|
|
|
73
|
1
|
229
|
my ( $self, $elem, undef ) = @_; |
57
|
|
|
|
|
|
|
|
58
|
73
|
100
|
|
|
|
272
|
return if $elem->type() ne 'no'; |
59
|
10
|
50
|
|
|
|
320
|
return if $elem->pragma() ne 'strict'; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
#Arguments to 'no strict' are usually a list of literals or a qw() |
62
|
|
|
|
|
|
|
#list. Rather than trying to parse the various PPI elements, I |
63
|
|
|
|
|
|
|
#just use a regex to split the statement into words. This is |
64
|
|
|
|
|
|
|
#kinda lame, but it does the trick for now. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# TODO consider: a possible alternate implementation: |
67
|
|
|
|
|
|
|
# my $re = join q{|}, keys %{$self->{allow}}; |
68
|
|
|
|
|
|
|
# return if $re && $stmnt =~ m/\b(?:$re)\b/mx; |
69
|
|
|
|
|
|
|
# May need to detaint for that to work... Not sure. |
70
|
|
|
|
|
|
|
|
71
|
10
|
|
|
|
|
402
|
my $stmnt = $elem->statement(); |
72
|
10
|
50
|
|
|
|
158
|
return if !$stmnt; |
73
|
10
|
|
|
|
|
38
|
my @words = $stmnt =~ m/ ([[:lower:]]+) /gxms; |
74
|
10
|
100
|
100
|
|
|
402
|
@words = grep { $_ ne 'qw' && $_ ne 'no' && $_ ne 'strict' } @words; |
|
48
|
|
|
|
|
245
|
|
75
|
10
|
100
|
100
|
19
|
|
98
|
return if @words && all { exists $self->{_allow}->{$_} } @words; |
|
19
|
|
|
|
|
87
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
#If we get here, then it must be a violation |
78
|
6
|
|
|
|
|
47
|
return $self->violation( $DESC, $EXPL, $elem ); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
__END__ |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=pod |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 NAME |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Perl::Critic::Policy::TestingAndDebugging::ProhibitNoStrict - Prohibit various flavors of C<no strict>. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 AFFILIATION |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
This Policy is part of the core L<Perl::Critic|Perl::Critic> |
97
|
|
|
|
|
|
|
distribution. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 DESCRIPTION |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
There are good reasons for disabling certain kinds of strictures, But |
103
|
|
|
|
|
|
|
if you were wise enough to C<use strict> in the first place, then it |
104
|
|
|
|
|
|
|
doesn't make sense to disable it completely. By default, any C<no |
105
|
|
|
|
|
|
|
strict> statement will violate this policy. However, you can |
106
|
|
|
|
|
|
|
configure this Policy to allow certain types of strictures to be |
107
|
|
|
|
|
|
|
disabled (See L</CONFIGURATION>). A bare C<no strict> statement will |
108
|
|
|
|
|
|
|
always raise a violation. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 CONFIGURATION |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
The permitted strictures can be configured via the C<allow> option. |
114
|
|
|
|
|
|
|
The value is a list of whitespace-delimited stricture types that you |
115
|
|
|
|
|
|
|
want to permit. These can be C<vars>, C<subs> and/or C<refs>. An |
116
|
|
|
|
|
|
|
example of this customization: |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
[TestingAndDebugging::ProhibitNoStrict] |
119
|
|
|
|
|
|
|
allow = vars subs refs |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 SEE ALSO |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
L<Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict|Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict> |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 AUTHOR |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 COPYRIGHT |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Copyright (c) 2005-2021 Imaginative Software Systems. All rights reserved. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
137
|
|
|
|
|
|
|
it under the same terms as Perl itself. The full text of this license |
138
|
|
|
|
|
|
|
can be found in the LICENSE file included with this module |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
############################################################################## |
143
|
|
|
|
|
|
|
# Local Variables: |
144
|
|
|
|
|
|
|
# mode: cperl |
145
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
146
|
|
|
|
|
|
|
# fill-column: 78 |
147
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
148
|
|
|
|
|
|
|
# c-indentation-style: bsd |
149
|
|
|
|
|
|
|
# End: |
150
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |