From 6a7d850e1b1c4a34f69bac2a99fbb74c32e256df Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Sat, 8 Apr 2017 20:29:10 +0300 Subject: [PATCH 1/1] Add perlcritic tests and make code clean --- MANIFEST | 2 ++ lib/Mafia.pm | 20 ++++++++++---------- t/perlcritic.t | 10 ++++++++++ t/perlcriticrc | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 t/perlcritic.t create mode 100644 t/perlcriticrc diff --git a/MANIFEST b/MANIFEST index 2caf3fe..9a3730d 100644 --- 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 diff --git a/lib/Mafia.pm b/lib/Mafia.pm index 2b943b4..5c3f788 100644 --- a/lib/Mafia.pm +++ b/lib/Mafia.pm @@ -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 index 0000000..e005e07 --- /dev/null +++ b/t/perlcritic.t @@ -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 index 0000000..1e7f484 --- /dev/null +++ b/t/perlcriticrc @@ -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 -- 2.39.2