File Coverage

blib/lib/Perl/Critic/Policy/Bangs/ProhibitCommentedOutCode.pm
Criterion Covered Total %
statement 21 22 95.4
branch 2 2 100.0
condition n/a
subroutine 8 9 88.8
pod 4 5 80.0
total 35 38 92.1


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::Bangs::ProhibitCommentedOutCode;
2              
3 5     5   2757 use strict;
  5         11  
  5         119  
4 5     5   22 use warnings;
  5         10  
  5         92  
5 5     5   24 use Perl::Critic::Utils;
  5         11  
  5         62  
6 5     5   3642 use base 'Perl::Critic::Policy';
  5         11  
  5         879  
7              
8             our $VERSION = '1.12';
9              
10             #---------------------------------------------------------------------------
11              
12             sub supported_parameters {
13             return (
14             {
15 10     10 0 43869 name => 'commentedcoderegex',
16             description => 'Regular expression to use to look for code in comments.',
17             behavior => 'string',
18             default_string => '\$[A-Za-z_].*=', ## no critic (RequireInterpolationOfMetachars)
19             },
20             );
21             }
22              
23 5     5 1 64 sub default_severity { return $SEVERITY_LOW }
24 0     0 1 0 sub default_themes { return qw( bangs maintenance ) }
25 6     6 1 37707 sub applies_to { return 'PPI::Token::Comment' }
26              
27             #---------------------------------------------------------------------------
28              
29             sub violates {
30 17     17 1 1109 my ( $self, $elem, $doc ) = @_;
31              
32 17 100       134 if ( $elem =~ $self->{_commentedcoderegex} ) {
33 5         40 my $desc = q(Code found in comment);
34 5         11 my $expl = q(Commented-out code found can be confusing);
35 5         27 return $self->violation( $desc, $expl, $elem );
36             }
37              
38 12         74 return;
39             }
40              
41             1;
42              
43             __END__
44             =for stopwords regex
45              
46             =head1 NAME
47              
48             Perl::Critic::Policy::Bangs::ProhibitCommentedOutCode - Commented-out code is usually noise. It should be removed.
49              
50             =head1 AFFILIATION
51              
52             This Policy is part of the L<Perl::Critic::Bangs> distribution.
53              
54             =head1 DESCRIPTION
55              
56             Commented-out code is often a sign of a place where the developer
57             is unsure of how the code should be. If historical information
58             about the code is important, then keep it in your version control
59             system.
60              
61             =head1 CONFIGURATION
62              
63             By default, this policy attempts to look for commented out code by
64             looking for variable assignments in code as represented by the regular
65             expression C<qr/\$[A-Za-z_].*=/> found in a comment. You can change
66             that regex by specifying a value for C<commentedcoderegex>.
67              
68             [Bangs::ProhibitCommentedOutCode]
69             commentedcoderegex = \$[A-Za-z_].*=/
70              
71             =head1 AUTHOR
72              
73             Andrew Moore C<< amoore@mooresystems.com >>
74              
75             =head1 ACKNOWLEDGMENTS
76              
77             Adapted from policies by Jeffrey Ryan Thalhammer <thaljef@cpan.org>,
78             Based on App::Fluff by Andy Lester, "<andy at petdance.com>"
79              
80             =head1 COPYRIGHT
81              
82             Copyright (C) 2006-2017 Andy Lester and Andrew Moore
83              
84             This library is free software; you can redistribute it and/or modify
85             it under the terms of the Artistic License 2.0.
86              
87             =cut