Perl::Critic::Policy::Bangs::ProhibitCommentedOutCode - Commented-out code is usually noise. It should be removed.


Perl-Critic-Bangs documentation Contained in the Perl-Critic-Bangs distribution.

Index


Code Index:

NAME

Top

Perl::Critic::Policy::Bangs::ProhibitCommentedOutCode - Commented-out code is usually noise. It should be removed.

AFFILIATION

Top

This Policy is part of the Perl::Critic::Bangs distribution.

DESCRIPTION

Top

Commented-out code is often a sign of a place where the developer is unsure of how the code should be. If historical information about the code is important, then keep it in your version control system.

CONFIGURATION

Top

By default, this policy attempts to look for commented out code by looking for variable assignments in code as represented by the regular expression qr/\$[A-Za-z_].*=/ found in a comment. You can change that regex by specifying a value for coderegex.

  [Bangs::ProhibitCommentedOutCode]
  coderegex = \$[A-Za-z_].*=/

AUTHOR

Top

Andrew Moore <amoore@mooresystems.com>

ACKNOWLEDGMENTS

Top

Adapted from policies by Jeffrey Ryan Thalhammer <thaljef@cpan.org>, Based on App::Fluff by Andy Lester, "<andy at petdance.com>"

COPYRIGHT

Top


Perl-Critic-Bangs documentation Contained in the Perl-Critic-Bangs distribution.

package Perl::Critic::Policy::Bangs::ProhibitCommentedOutCode;

use strict;
use warnings;
use Perl::Critic::Utils;
use base 'Perl::Critic::Policy';

our $VERSION = '1.08';

#---------------------------------------------------------------------------

sub supported_parameters {
    return (
        {
            name           => 'commentedcoderegex',
            description    => 'Regular expression to use to look for code in comments.',
            behavior       => 'string',
            default_string => '\$[A-Za-z_].*=', ## no critic (RequireInterpolationOfMetachars)
        },
    );
}

sub default_severity     { return $SEVERITY_LOW           }
sub default_themes       { return qw( bangs maintenance ) }
sub applies_to           { return 'PPI::Token::Comment'   }

#---------------------------------------------------------------------------

sub violates {
    my ( $self, $elem, $doc ) = @_;
    my @viols = ();

    my $nodes = $doc->find( 'PPI::Token::Comment' );

    if ( $elem =~ $self->{_commentedcoderegex} ) {
        my $desc = q(Code found in comment);
        my $expl = q(Commented-out code found can be confusing);
        return $self->violation( $desc, $expl, $elem );
    }
    return;
}

1;

__END__

#---------------------------------------------------------------------------