A new, better-coded PerlCritic script customized for Auto as we have a Damn Good Reason (DGR) to bend some of the rules.

This commit is contained in:
Elijah Perrault committed 2011-02-07 13:45:24 -07:00
1 parent 338ccf4e16
commit 2e7ffc6a6f
1 file changed
+56
Executable
+56
View File
@@ -0,0 +1,56 @@
#!/usr/bin/env perl
# Auto IRC Bot. An advanced, lightweight and powerful IRC bot.
# Copyright (C) 2010-2011 Xelhua Development Team (doc/CREDITS)
# This program is free software; rights to this code are stated in doc/LICENSE.
require 5.010000;
use strict;
use warnings;
use feature qw(say);
use Perl::Critic;
# Set default severity to 1.
my $severity = 1;
if (!defined $ARGV[0]) {
# Missing parameter file.
say 'Not enough parameters. Usage: <file> [level]';
say 'Levels: 1/brutal, 2/cruel, 3/harsh, 4/stern, 5/gentle';
}
if (defined $ARGV[1]) {
# If a different severity was passed, get it.
my $ts = $ARGV[1];
$ts = lc($ts);
if ($ts =~ m/^(1|2|3|4|5|brutal|cruel|harsh|stern|gentle)/xsm) {
# If it's valid, set severity to it.
$severity = $ts;
}
}
# Create an instance of Perl::Critic, excluding certain Policies.
my $critic = Perl::Critic->new(-exclude => ['Perl::Critic::Policy::Miscellanea::RequireRcsKeywords',
'Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation',
'Perl::Critic::Policy::Modules::ProhibitExcessMainComplexity',
'Perl::Critic::Policy::InputOutput::ProhibitBacktickOperators',
'Perl::Critic::Policy::CodeLayout::RequireTidyCode'], -severity => $severity);
# Get violations.
my @violations = $critic->critique($ARGV[0]);
my $count = 0;
if (!defined $violations[0]) {
# No violations! :D
say "No violations. $ARGV[0] has passed!";
exit;
}
# There was some violations. Lets list them.
say 'Violations:';
foreach (@violations) {
$count++;
say $_;
}
say "$count violations in $ARGV[0].";