Login
Created a new Policy to prohibit an unrestricted ## no critic.
[gknop/Perl-Critic.git] / lib / Perl / Critic / Policy / Miscellanea / ProhibitUnrestrictedNoCritic.pm
CommitLineData
05e2d404
JRT
1##############################################################################
2# $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/Miscellanea/ProhibitFormats.pm $
3# $Date: 2008-09-07 03:33:32 -0700 (Sun, 07 Sep 2008) $
4# $Author: clonezone $
5# $Revision: 2730 $
6##############################################################################
7
8package Perl::Critic::Policy::Miscellanea::ProhibitUnrestrictedNoCritic;
9
10use 5.006001;
11use strict;
12use warnings;
13use Readonly;
14
15use Perl::Critic::Utils qw<:severities :booleans>;
16use base 'Perl::Critic::Policy';
17
18our $VERSION = '1.093_01';
19
20#-----------------------------------------------------------------------------
21
22Readonly::Scalar my $DESC => q{Unrestriced '## no critic' pseudo-pragma};
23Readonly::Scalar my $EXPL => q{Only disable the Policies you really need to disable};
24
25#-----------------------------------------------------------------------------
26
27sub supported_parameters { return () }
28sub default_severity { return $SEVERITY_MEDIUM }
29sub default_themes { return qw( core maintenance ) }
30sub applies_to { return 'PPI::Token::Comment' }
31sub can_be_disabled { return $FALSE }
32
33#-----------------------------------------------------------------------------
34
35sub violates {
36 my ( $self, $elem, undef ) = @_;
37 return if $elem !~ m{\A \#\# \s+ no \s+ critic \b}smx;
38
39 if ($elem !~ m{\A \#\# \s+ no \s+ critic \s* (?: qw)? \( .+ \)}smx ) {
40 return $self->violation( $DESC, $EXPL, $elem );
41 }
42
43 return; # ok!
44}
45
46
471;
48
49__END__
50
51#-----------------------------------------------------------------------------
52
53=pod
54
55=head1 NAME
56
57Perl::Critic::Policy::Miscellanea::ProhibitUnrestrictedNoCritic - Forbid a bare C<## no critic>
58
59
60=head1 AFFILIATION
61
62This Policy is part of the core L<Perl::Critic|Perl::Critic>
63distribution.
64
65
66=head1 DESCRIPTION
67
68A bare C<## no critic> marker will disable B<all> the active Policies.
69This creates holes for other, unintended violations to appear in your code. It is
70better to disable B<only> the particular Policies that you need to get around.
71By putting Policy names in parenthsis after the C<## no critic> marker, then
72it will only disable the named Policies. Policy names are matched as regular
73expressions, so you can use shortened Policy names, or patterns that match
74several Policies. This Policy generates a violation any time that an
75unrestricted C<## no critic> marker appears.
76
77 ## no critic # not ok
78 ## no critic () # not ok
79 ## no critic (SomePolicyNames) # ok
80
81=head1 CONFIGURATION
82
83This Policy is not configurable except for the standard options.
84
85
86=head1 AUTHOR
87
88Jeffrey Ryan Thalhammer <thaljef@cpan.org>
89
90=head1 COPYRIGHT
91
92Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer. All rights reserved.
93
94This program is free software; you can redistribute it and/or modify
95it under the same terms as Perl itself. The full text of this license
96can be found in the LICENSE file included with this module.
97
98=cut
99
100# Local Variables:
101# mode: cperl
102# cperl-indent-level: 4
103# fill-column: 78
104# indent-tabs-mode: nil
105# c-indentation-style: bsd
106# End:
107# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :