]> iEval git - mafia.git/commitdiff
Add perlcritic tests and make code clean
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 8 Apr 2017 17:29:10 +0000 (20:29 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 8 Apr 2017 17:29:10 +0000 (20:29 +0300)
MANIFEST
lib/Mafia.pm
t/perlcritic.t [new file with mode: 0644]
t/perlcriticrc [new file with mode: 0644]

index 2caf3fe95a5e0e8a16fc187e6224b7ac281bc850..9a3730d1f27dd4cd7397ed95f037b7962b9be7c5 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -13,4 +13,6 @@ t/examples/Newbie-0004.out
 t/examples/Newbie-0002.pl
 t/examples/Newbie-0005.pl
 t/examples/Newbie-0002.out
+t/perlcritic.t
+t/perlcriticrc
 lib/Mafia.pm
index 2b943b4ddf7b6f68448cd3f73ecf547644e8ad15..5c3f788d2a04006d31fa8c1a9c2d62fc6195c147 100644 (file)
@@ -29,7 +29,7 @@ BEGIN {
        defconst qw/ACT_KILL ACT_LYNCH ACT_PROTECT ACT_GUARD ACT_ROLEBLOCK ACT_GUNCHECK ACT_TRACK ACT_WATCH ACT_ROLECOP ACT_COP ACT_TRACK_RESULT ACT_WATCH_RESULT ACT_HIDE/;
 }
 
-use constant +{
+use constant +{ ## no critic (Capitalization)
        townie => town,
        ROLE => [vanilla, goon, doctor, vigilante, roleblocker, jailkeeper, gunsmith, tracker, watcher, bodyguard, rolecop, cop, sk, hider],
        FACTION => [mafia, town],
@@ -46,7 +46,7 @@ my %INVESTIGATIVE_ACTIONS_HASH = map { $_ => 1 } @{INVESTIGATIVE_ACTIONS()};
 my %GUNROLES_HASH = map { $_ => 1 } @{GUNROLES()};
 
 our @EXPORT = do {
-       no strict 'refs';
+       no strict 'refs'; ## no critic (ProhibitNoStrict)
        grep { $_ !~ [qw/import/] and exists &$_ } keys %{__PACKAGE__ . '::'};
 };
 
@@ -83,7 +83,7 @@ sub phase {
        return "Night $nightcnt" unless $isday;
 }
 
-sub rolename {
+sub rolename { ## no critic (RequireArgUnpacking)
        my %player = %{$players{$_[0]}};
        my ($faction, $role) = ($player{faction}, $player{role});
        if (defined $faction && $faction eq town && $role eq vanilla) {
@@ -118,7 +118,7 @@ sub msg {
 
                MSG_PLAYERS_ALIVE => sub {
                        @args = sort @args;
-                       say "Players alive: ", join ', ', @args
+                       say 'Players alive: ', join ', ', @args
                },
 
                MSG_DEATH => sub {
@@ -186,7 +186,7 @@ sub putaction {
        push @{$actions[$delay]->{$type}}, \%args
 }
 
-sub doaction {
+sub doaction { ## no critic (ProhibitExcessComplexity)
        my ($type, $args) = @_;
        my %args = %$args;
        my $source = $args{source};
@@ -201,10 +201,10 @@ sub doaction {
                # Copy this action to everybody hiding behind $target
                if (exists $tplayers{$target}{hiders}) {
                        for my $target (@{$tplayers{$target}{hiders}}) {
-                               my %args = %args;
-                               $args{target} = $target;
-                               $args{hidepierce} = 1;
-                               doaction($type, \%args);
+                               my %new_args = %args;
+                               $new_args{target} = $target;
+                               $new_args{hidepierce} = 1;
+                               doaction($type, \%new_args);
                        }
                }
 
@@ -446,7 +446,7 @@ Mafia - easily moderate Mafia games
 
   night;
 
-=head1 DESCRPTION
+=head1 DESCRIPTION
 
 Mafia.pm is a Perl extension for easily moderating Mafia games. You don't even need to know Perl to use it (see L<"WHAT YOU NEED TO KNOW"> for details).
 
diff --git a/t/perlcritic.t b/t/perlcritic.t
new file mode 100644 (file)
index 0000000..e005e07
--- /dev/null
@@ -0,0 +1,10 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+use Test::More;
+
+BEGIN { plan skip_all => '$ENV{RELEASE_TESTING} is false' unless $ENV{RELEASE_TESTING} }
+use Test::Perl::Critic -profile => 't/perlcriticrc';
+
+all_critic_ok 'lib'
diff --git a/t/perlcriticrc b/t/perlcriticrc
new file mode 100644 (file)
index 0000000..1e7f484
--- /dev/null
@@ -0,0 +1,43 @@
+severity = 1
+
+[-BuiltinFunctions::ProhibitComplexMappings]
+[-CodeLayout::RequireTidyCode]
+[-ControlStructures::ProhibitPostfixControls]
+[-ControlStructures::ProhibitUnlessBlocks]
+[-Documentation::PodSpelling]
+[-Documentation::RequirePodLinksIncludeText]
+[-InputOutput::RequireBracedFileHandleWithPrint]
+[-InputOutput::RequireCheckedClose]
+[-InputOutput::RequireCheckedSyscalls]
+[-Modules::ProhibitAutomaticExportation]
+[-References::ProhibitDoubleSigils]
+[-RegularExpressions::ProhibitEnumeratedClasses]
+[-RegularExpressions::ProhibitUnusualDelimiters]
+[-RegularExpressions::RequireBracesForMultiline]
+[-RegularExpressions::RequireLineBoundaryMatching]
+[-Subroutines::RequireFinalReturn]
+[-ValuesAndExpressions::ProhibitConstantPragma]
+[-ValuesAndExpressions::ProhibitEmptyQuotes]
+[-ValuesAndExpressions::ProhibitLeadingZeros]
+[-ValuesAndExpressions::ProhibitMagicNumbers]
+[-ValuesAndExpressions::ProhibitNoisyQuotes]
+[-Variables::ProhibitLocalVars]
+[-Variables::ProhibitPackageVars]
+[-Variables::ProhibitPunctuationVars]
+
+[BuiltinFunctions::ProhibitStringyEval]
+allow_includes = 1
+
+[RegularExpressions::RequireExtendedFormatting]
+minimum_regex_length_to_complain_about = 20
+
+[Documentation::RequirePodSections]
+lib_sections = NAME | SYNOPSIS | DESCRIPTION | AUTHOR | COPYRIGHT AND LICENSE
+script_sections = NAME | SYNOPSIS | DESCRIPTION | AUTHOR | COPYRIGHT AND LICENSE
+
+[Subroutines::RequireArgUnpacking]
+short_subroutine_statements = 5
+allow_subscripts = 1
+
+[TestingAndDebugging::ProhibitNoWarnings]
+allow_with_category_restriction = 1
This page took 0.034423 seconds and 4 git commands to generate.