| 1 | # | ||||||||||||||||||||||||||||
| 2 | # This file is part of Test-Apocalypse | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # This software is copyright (c) 2014 by Apocalypse. | ||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||
| 9 | 38 | ▶ | use strict; use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | package Test::Apocalypse::PerlCritic; | ||||||||||||||||||||||||||||
| 11 | 38 | $Test::Apocalypse::PerlCritic::VERSION = '1.006'; | |||||||||||||||||||||||||||
| 12 | 38 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 38 | $Test::Apocalypse::PerlCritic::AUTHORITY = 'cpan:APOCAL'; | |||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # ABSTRACT: Plugin for Test::Perl::Critic | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 38 | ▶ | use Test::More; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 38 | ▶ | use Test::Perl::Critic 1.02; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 38 | ▶ | use File::Spec 3.31; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | # This is so we always have all PerlCritic plugins installed, yay! | ||||||||||||||||||||||||||||
| 23 | 38 | ▶ | use Task::Perl::Critic 1.007; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 38 | ▶ | use Perl::Critic::Itch 0.07; # for CodeLayout::ProhibitHashBarewords | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 38 | ▶ | use Perl::Critic::Deprecated 1.108; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 37 | ▶ | sub _do_automated { 0 } | ||||||||||||||||||||||||||
|
Subroutine
_do_automated: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub do_test { | ||||||||||||||||||||||||||
|
Subroutine
do_test: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | # set default opts | ||||||||||||||||||||||||||||
| 31 | 0 | require Perl::Critic::Utils::Constants; | |||||||||||||||||||||||||||
| 32 | 0 | my %opts = ( | |||||||||||||||||||||||||||
| 33 | '-verbose' => "[%p] %m at line %l, near '%r'\n", | ||||||||||||||||||||||||||||
| 34 | '-severity' => 'brutal', | ||||||||||||||||||||||||||||
| 35 | '-profile-strictness' => $Perl::Critic::Utils::Constants::PROFILE_STRICTNESS_FATAL, | ||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # Do we have a perlcriticrc? | ||||||||||||||||||||||||||||
| 39 | 0 | my $rcfile = File::Spec->catfile( 't', 'perlcriticrc' ); | |||||||||||||||||||||||||||
| 40 | 0 | my $default_rcfile; # did we generate a default? | |||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ( ! -e $rcfile ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | # Maybe it's in the CWD? | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ( ! -e 'perlcriticrc' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | # Generate it using the default! | ||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if ( ! -d 't' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | # We're already in the test dir | ||||||||||||||||||||||||||||
| 47 | 0 | $rcfile = 'perlcriticrc'; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | open( my $rc, '>', $rcfile ) or die "Unable to open $rcfile for writing: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | print $rc _default_perlcriticrc(); | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | close $rc or die "Unable to close $rcfile: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | $default_rcfile = 1; | |||||||||||||||||||||||||||
| 54 | } else { | ||||||||||||||||||||||||||||
| 55 | 0 | $rcfile = 'perlcriticrc'; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | 0 | Test::Perl::Critic->import( %opts, '-profile' => $rcfile ); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | TODO: { | ||||||||||||||||||||||||||||
| 61 | 0 | local $TODO = "PerlCritic"; | |||||||||||||||||||||||||||
| 62 | 0 | all_critic_ok(); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ( $default_rcfile ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | unlink $rcfile or die "Unable to remove $rcfile: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | return; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub _default_perlcriticrc { | ||||||||||||||||||||||||||
|
Subroutine
_default_perlcriticrc: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 73 | # Build a default file | ||||||||||||||||||||||||||||
| 74 | 0 | my $rcfile = <<'EOF'; | |||||||||||||||||||||||||||
| 75 | # If you're wondering why there's a gazillion exclusions in here... | ||||||||||||||||||||||||||||
| 76 | # It's because I installed every Perl::Critic policy there is ;) | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # --------------------------------------------- | ||||||||||||||||||||||||||||
| 79 | # Policies that is already covered by other tests in Test::Apocalypse | ||||||||||||||||||||||||||||
| 80 | # --------------------------------------------- | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | [-Compatibility::PerlMinimumVersionAndWhy] | ||||||||||||||||||||||||||||
| 83 | [-Modules::RequirePerlVersion] | ||||||||||||||||||||||||||||
| 84 | # covered by MinimumVersion | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | [-Documentation::PodSpelling] | ||||||||||||||||||||||||||||
| 87 | # covered by Pod_Spelling | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | # --------------------------------------------- | ||||||||||||||||||||||||||||
| 90 | # editor/style stuff that is too strict | ||||||||||||||||||||||||||||
| 91 | # --------------------------------------------- | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | [-Bangs::ProhibitCommentedOutCode] | ||||||||||||||||||||||||||||
| 94 | [-Bangs::ProhibitFlagComments] | ||||||||||||||||||||||||||||
| 95 | [-Bangs::ProhibitVagueNames] | ||||||||||||||||||||||||||||
| 96 | [-CodeLayout::ProhibitHardTabs] | ||||||||||||||||||||||||||||
| 97 | [-CodeLayout::ProhibitParensWithBuiltins] | ||||||||||||||||||||||||||||
| 98 | [-CodeLayout::RequireTidyCode] | ||||||||||||||||||||||||||||
| 99 | [-CodeLayout::RequireTrailingCommaAtNewline] | ||||||||||||||||||||||||||||
| 100 | [-CodeLayout::RequireUseUTF8] | ||||||||||||||||||||||||||||
| 101 | [-Documentation::RequirePodLinksIncludeText] | ||||||||||||||||||||||||||||
| 102 | [-Documentation::RequirePODUseEncodingUTF8] | ||||||||||||||||||||||||||||
| 103 | [-Documentation::ProhibitUnbalancedParens] | ||||||||||||||||||||||||||||
| 104 | [-Editor::RequireEmacsFileVariables] | ||||||||||||||||||||||||||||
| 105 | [-Miscellanea::RequireRcsKeywords] | ||||||||||||||||||||||||||||
| 106 | [-Modules::ProhibitExcessMainComplexity] | ||||||||||||||||||||||||||||
| 107 | [-NamingConventions::Capitalization] | ||||||||||||||||||||||||||||
| 108 | [-NamingConventions::ProhibitMixedCaseVars] | ||||||||||||||||||||||||||||
| 109 | [-Subroutines::ProhibitExcessComplexity] | ||||||||||||||||||||||||||||
| 110 | [-Subroutines::ProhibitSubroutinePrototypes] | ||||||||||||||||||||||||||||
| 111 | [-Tics::ProhibitLongLines] | ||||||||||||||||||||||||||||
| 112 | [-ValuesAndExpressions::ProhibitEscapedCharacters] | ||||||||||||||||||||||||||||
| 113 | [-ValuesAndExpressions::ProhibitLongChainsOfMethodCalls] | ||||||||||||||||||||||||||||
| 114 | [-ValuesAndExpressions::ProhibitMagicNumbers] | ||||||||||||||||||||||||||||
| 115 | [-ValuesAndExpressions::ProhibitNoisyQuotes] | ||||||||||||||||||||||||||||
| 116 | [-ValuesAndExpressions::RestrictLongStrings] | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | # --------------------------------------------- | ||||||||||||||||||||||||||||
| 119 | # miscellaneous policies that is just plain annoying | ||||||||||||||||||||||||||||
| 120 | # --------------------------------------------- | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | [-BuiltinFunctions::ProhibitStringyEval] | ||||||||||||||||||||||||||||
| 123 | [-BuiltinFunctions::ProhibitStringySplit] | ||||||||||||||||||||||||||||
| 124 | [-BuiltinFunctions::ProhibitUselessTopic] | ||||||||||||||||||||||||||||
| 125 | [-Compatibility::ProhibitThreeArgumentOpen] | ||||||||||||||||||||||||||||
| 126 | [-ControlStructures::ProhibitCascadingIfElse] | ||||||||||||||||||||||||||||
| 127 | [-ControlStructures::ProhibitDeepNests] | ||||||||||||||||||||||||||||
| 128 | [-ControlStructures::ProhibitPostfixControls] | ||||||||||||||||||||||||||||
| 129 | [-ErrorHandling::RequireCarping] | ||||||||||||||||||||||||||||
| 130 | [-ErrorHandling::RequireCheckingReturnValueOfEval] | ||||||||||||||||||||||||||||
| 131 | [-ErrorHandling::RequireUseOfExceptions] | ||||||||||||||||||||||||||||
| 132 | [-InputOutput::RequireBracedFileHandleWithPrint] | ||||||||||||||||||||||||||||
| 133 | [-InputOutput::RequireBriefOpen] | ||||||||||||||||||||||||||||
| 134 | [-InputOutput::RequireCheckedSyscalls] | ||||||||||||||||||||||||||||
| 135 | [-Lax::ProhibitEmptyQuotes::ExceptAsFallback] | ||||||||||||||||||||||||||||
| 136 | [-Lax::ProhibitStringyEval::ExceptForRequire] | ||||||||||||||||||||||||||||
| 137 | [-Miscellanea::ProhibitTies] | ||||||||||||||||||||||||||||
| 138 | [-Modules::ProhibitAutomaticExportation] | ||||||||||||||||||||||||||||
| 139 | [-Modules::RequireBarewordIncludes] | ||||||||||||||||||||||||||||
| 140 | [-Modules::RequireExplicitPackage] | ||||||||||||||||||||||||||||
| 141 | [-NamingConventions::ProhibitMixedCaseSubs] | ||||||||||||||||||||||||||||
| 142 | [-References::ProhibitDoubleSigils] | ||||||||||||||||||||||||||||
| 143 | [-RegularExpressions::ProhibitEscapedMetacharacters] | ||||||||||||||||||||||||||||
| 144 | [-RegularExpressions::ProhibitFixedStringMatches] | ||||||||||||||||||||||||||||
| 145 | [-RegularExpressions::RequireDotMatchAnything] | ||||||||||||||||||||||||||||
| 146 | [-RegularExpressions::RequireExtendedFormatting] | ||||||||||||||||||||||||||||
| 147 | [-RegularExpressions::RequireLineBoundaryMatching] | ||||||||||||||||||||||||||||
| 148 | [-RegularExpressions::ProhibitUselessTopic] | ||||||||||||||||||||||||||||
| 149 | [-Subroutines::ProhibitCallsToUndeclaredSubs] | ||||||||||||||||||||||||||||
| 150 | [-Subroutines::ProhibitCallsToUnexportedSubs] | ||||||||||||||||||||||||||||
| 151 | [-Subroutines::ProhibitManyArgs] | ||||||||||||||||||||||||||||
| 152 | [-Subroutines::ProhibitUnusedPrivateSubroutines] | ||||||||||||||||||||||||||||
| 153 | [-Subroutines::ProtectPrivateSubs] | ||||||||||||||||||||||||||||
| 154 | [-Subroutines::RequireArgUnpacking] | ||||||||||||||||||||||||||||
| 155 | [-Subroutines::RequireFinalReturn] | ||||||||||||||||||||||||||||
| 156 | [-TestingAndDebugging::ProhibitNoStrict] | ||||||||||||||||||||||||||||
| 157 | [-TestingAndDebugging::ProhibitNoWarnings] | ||||||||||||||||||||||||||||
| 158 | [-ValuesAndExpressions::ProhibitAccessOfPrivateData] | ||||||||||||||||||||||||||||
| 159 | [-ValuesAndExpressions::ProhibitCommaSeparatedStatements] | ||||||||||||||||||||||||||||
| 160 | [-ValuesAndExpressions::ProhibitEmptyQuotes] | ||||||||||||||||||||||||||||
| 161 | [-ValuesAndExpressions::ProhibitFiletest_f] | ||||||||||||||||||||||||||||
| 162 | [-ValuesAndExpressions::ProhibitInterpolationOfLiterals] | ||||||||||||||||||||||||||||
| 163 | [-ValuesAndExpressions::RequireInterpolationOfMetachars] | ||||||||||||||||||||||||||||
| 164 | [-Variables::ProhibitLocalVars] | ||||||||||||||||||||||||||||
| 165 | [-Variables::ProhibitPunctuationVars] | ||||||||||||||||||||||||||||
| 166 | [-Variables::ProhibitPackageVars] | ||||||||||||||||||||||||||||
| 167 | [-Variables::RequireInitializationForLocalVars] | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | EOF | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | # Ignore optional stuff? | ||||||||||||||||||||||||||||
| 172 | 0 | ▶ | unless ( exists $ENV{'PERL_CRITIC_STRICT'} and $ENV{'PERL_CRITIC_STRICT'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $ENV{"PERL_CRITIC_STRICT"} and $ENV{"PERL_CRITIC_STRICT"}
MC/DC0%0/2
exists $ENV{"PERL_CRITIC_STRICT"} and $ENV{"PERL_CRITIC_STRICT"}
exists $ENV{"PERL_CRITIC_STRICT"}
$ENV{"PERL_CRITIC_STRICT"}
Truth table0%0/3
A and B
A= exists $ENV{"PERL_CRITIC_STRICT"}B= $ENV{"PERL_CRITIC_STRICT"}
| |||||||||||||||||||||||||||||
| 173 | 0 | $rcfile .= <<'EOF'; | |||||||||||||||||||||||||||
| 174 | # --------------------------------------------- | ||||||||||||||||||||||||||||
| 175 | # TODO probably sane policies but need to do a lot of work to fix them... | ||||||||||||||||||||||||||||
| 176 | # --------------------------------------------- | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | [-CodeLayout::ProhibitHashBarewords] | ||||||||||||||||||||||||||||
| 179 | # sometimes we're lazy! | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | [-Compatibility::PodMinimumVersion] | ||||||||||||||||||||||||||||
| 182 | # there should be a Test::Apocalypse check for that! | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | [-ControlStructures::ProhibitUnlessBlocks] | ||||||||||||||||||||||||||||
| 185 | # it's so easy to be lazy! | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | [-Documentation::RequirePodSections] | ||||||||||||||||||||||||||||
| 188 | # what is the "default" list? Obviously not PBP because it requires way too much sections! | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | [-Miscellanea::ProhibitUselessNoCritic] | ||||||||||||||||||||||||||||
| 191 | # I don't want to go through my old code and clean them up... laziness again! | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | [-Modules::RequireExplicitInclusion] | ||||||||||||||||||||||||||||
| 194 | # while this makes sense sometimes it's a drag to list the modules that you *know* a prereq will pull in... | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | [-RegularExpressions::ProhibitComplexRegexes] | ||||||||||||||||||||||||||||
| 197 | # while this is true it's unavoidable in some cases... | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | [-RegularExpressions::ProhibitUnusualDelimiters] | ||||||||||||||||||||||||||||
| 200 | # sometimes we like other delims... | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | [-Subroutines::ProhibitBuiltinHomonyms] | ||||||||||||||||||||||||||||
| 203 | # in POE "shutdown" is commonly used, also in some classes we define convenience methods like "print" and etc... | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | [-ValuesAndExpressions::ProhibitMixedBooleanOperators] | ||||||||||||||||||||||||||||
| 206 | # sometimes it feels "natural" to code in that style... | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | [-ValuesAndExpressions::ProhibitVersionStrings] | ||||||||||||||||||||||||||||
| 209 | # is this really a problem? If so, it's still a lot of work to go through code and figure out the proper string... | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | [-ValuesAndExpressions::RequireConstantOnLeftSideOfEquality] | ||||||||||||||||||||||||||||
| 212 | # I think "$^O eq 'MSWin32'" is valid... I don't want to rewrite tons of code just to satisfy this... | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | EOF | ||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 0 | return $rcfile; | |||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 38 | 1; | |||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | __END__ | ||||||||||||||||||||||||||||