blib/lib/Perl/Critic/Policy/Miscellanea/ProhibitUnrestrictedNoCritic.pm

filter: Statementstmt 90.9% 30 / 33 Branchbran 25.0% 1 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 80.0% 4 / 5 totaltotal 86.7% 46 / 53 CC 4 SCAR 8.9
CC
4
Cov
84%
violates
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.4
« blib/lib/Perl/Critic/Policy/Documentation/RequirePodAtEnd.pm ↑ Summary blib/lib/Perl/Critic/PolicyParameter/Behavior/StringList.pm »
1 package Perl::Critic::Policy::Miscellanea::ProhibitUnrestrictedNoCritic;
2  
3 40 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 40 ▶use Perl::Critic::Utils qw( :severities );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 40 our $VERSION = '1.150';
12  
13 #-----------------------------------------------------------------------------
14  
15 40 Readonly::Scalar my $DESC => q{Unrestricted '## no critic' annotation};
16 40 Readonly::Scalar my $EXPL => q{Only disable the Policies you really need to disable};
17  
18 #-----------------------------------------------------------------------------
19  
20 90 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
21 75 ▶sub default_severity { return $SEVERITY_MEDIUM }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
22 74 ▶sub default_themes { return qw( core maintenance ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
23 2 ▶sub applies_to { return 'PPI::Document' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
24  
25 #-----------------------------------------------------------------------------
26  
27 sub violates {
28 2 ▶ my ( $self, $doc, undef ) = @_;
Subroutine violates: called CC=4 SCAR=17.9
Pod documented
29  
30 # If for some reason $doc is not a P::C::Document, then all bets are off
31 2 ▶ return if not $doc->isa('Perl::Critic::Document');
Branch: 1 branch
BranchTrueFalseTotal
unless $doc->isa("Perl::Critic::Document") 0 2 2
32  
33 2 my @violations;
34 2 for my $annotation ($doc->annotations()) {
35 0 ▶ if ($annotation->disables_all_policies()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($annotation->disables_all_policies) 0 0 0
36 0 my $elem = $annotation->element();
37 0 push @violations, $self->violation($DESC, $EXPL, $elem);
38 }
39 }
40  
41 2 return @violations;
42 }
43  
44 #-----------------------------------------------------------------------------
45  
46 40 1;
47  
48 __END__
49  
50 #-----------------------------------------------------------------------------
51  
52 =pod
53  
54 =for stopwords syntaxes
55  
56 =head1 NAME
57  
58 Perl::Critic::Policy::Miscellanea::ProhibitUnrestrictedNoCritic - Forbid a bare C<## no critic>
59  
60  
61 =head1 AFFILIATION
62  
63 This Policy is part of the core L<Perl::Critic|Perl::Critic>
64 distribution.
65  
66  
67 =head1 DESCRIPTION
68  
69 A bare C<## no critic> annotation will disable B<all> the active Policies. This
70 creates holes for other, unintended violations to appear in your code. It is
71 better to disable B<only> the particular Policies that you need to get around.
72 By putting Policy names in a comma-separated list after the C<## no critic>
73 annotation, then it will only disable the named Policies. Policy names are
74 matched as regular expressions, so you can use shortened Policy names, or
75 patterns that match several Policies. This Policy generates a violation any
76 time that an unrestricted C<## no critic> annotation appears.
77  
78 ## no critic # not ok
79 ## no critic '' # not ok
80 ## no critic () # not ok
81 ## no critic qw() # not ok
82  
83 ## no critic (Policy1, Policy2) # ok
84 ## no critic (Policy1 Policy2) # ok (can use spaces to separate)
85 ## no critic qw(Policy1 Policy2) # ok (the preferred style)
86  
87  
88 =head1 NOTE
89  
90 Unfortunately, L<Perl::Critic|Perl::Critic> is very sloppy about
91 parsing the Policy names that appear after a C<##no critic>
92 annotation. For example, you might be using one of these
93 broken syntaxes...
94  
95 ## no critic Policy1 Policy2
96 ## no critic 'Policy1, Policy2'
97 ## no critic "Policy1, Policy2"
98 ## no critic "Policy1", "Policy2"
99  
100 In all of these cases, Perl::Critic will silently disable B<all> Policies,
101 rather than just the ones you requested. But if you use the
102 C<ProhibitUnrestrictedNoCritic> Policy, all of these will generate
103 violations. That way, you can track them down and correct them to use
104 the correct syntax, as shown above in the L<"DESCRIPTION">. If you've
105 been using the syntax that is shown throughout the Perl::Critic
106 documentation for the last few years, then you should be fine.
107  
108  
109 =head1 CONFIGURATION
110  
111 This Policy is not configurable except for the standard options.
112  
113  
114 =head1 AUTHOR
115  
116 Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
117  
118  
119 =head1 COPYRIGHT
120  
121 Copyright (c) 2008-2023 Imaginative Software Systems
122  
123 This program is free software; you can redistribute it and/or modify
124 it under the same terms as Perl itself. The full text of this license
125 can be found in the LICENSE file included with this module.
126  
127 =cut
128  
129 ###############################################################################
130 # Local Variables:
131 # mode: cperl
132 # cperl-indent-level: 4
133 # fill-column: 78
134 # indent-tabs-mode: nil
135 # c-indentation-style: bsd
136 # End:
137 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :
« blib/lib/Perl/Critic/Policy/Documentation/RequirePodAtEnd.pm ↑ Summary blib/lib/Perl/Critic/PolicyParameter/Behavior/StringList.pm »