From 8555dc411ee376fd103ab1572092f3f588784167 Mon Sep 17 00:00:00 2001 From: Andreas Romeyke <art1@andreas-romeyke.de> Date: Mon, 22 Feb 2021 11:50:32 +0100 Subject: [PATCH] - init --- .perlcriticrc | 217 ++++++++++++++++++++++++++++++++++++++++++++++++++ t/critic.t | 6 ++ t/eol.t | 6 ++ 3 files changed, 229 insertions(+) create mode 100644 .perlcriticrc create mode 100644 t/critic.t create mode 100644 t/eol.t diff --git a/.perlcriticrc b/.perlcriticrc new file mode 100644 index 0000000..fb7909a --- /dev/null +++ b/.perlcriticrc @@ -0,0 +1,217 @@ +#severity = gentle +severity = stern +only = 0 +force = 0 +verbose = 8 +top = 10 +theme = (core || pbp || security || bugs || complexity || maintenance || cosmetic || pulp || bangs ||certrec || certrule ) && !more +# more +color = 1 +# Tell us which rule this violated, so we can tell it to get lost +verbose = [%p] %m at %f line %l, near '%r'\n + +### rules + +### Git +# We use git, not svn or RCS +[-Miscellanea::RequireRcsKeywords] + +# We'll enforce dependencies in other ways, rather than magically putting +# a $VERSION variable in modules. +[-Modules::RequireVersionVar] + +### Modern Perl +# We'll run on at least perl 5.28 +[Compatibility::PodMinimumVersion] +above_version = 5.028 + +# So don't badger us about explicitly declaring which version of Perl we +# require +[-Compatibility::PerlMinimumVersionAndWhy] + +# Perltidy is a judgement call. +[-CodeLayout::RequireTidyCode] + +# Damian Conway's insistence that the literal '' or "" in a proper +# monospaced font is difficult to read is frankly bizarre. +[-ValuesAndExpressions::ProhibitEmptyQuotes] +[-ValuesAndExpressions::ProhibitNoisyQuotes] + +# reverse sort @array is indeed better than +# sort { $b cmp $a } @array +# I'm not so sure about hating on $b vs $a in e.g. +# sort { $b->{stuff} <=> $a->{stuff} } +[-BuiltinFunctions::ProhibitReverseSortBlock] + +# This is overridden by the better rule RequireCheckedSyscalls +[-InputOutput::RequireCheckedClose] + +# There's muscle memory of always adding /xms to a regex, and then there's +# typing for the hell of it. +[-RegularExpressions::RequireDotMatchAnything] +[-RegularExpressions::RequireLineBoundaryMatching] + +# Inline POD is good, dammit. +[-Documentation::RequirePodAtEnd] + +# These are internal Perl modules. They don't need all these sections. +[-Documentation::RequirePodSections] + +# We throw structured exceptions all the time. Carp would be a bad idea +# here. +[-ErrorHandling::RequireCarping] + + +### +[Bangs::ProhibitDebuggingModules] + severity = 3 +[Bangs::ProhibitNumberedNames] + exceptions = md5 utf8 sha1 sha2 sha512 + severity = 3 +## +[CodeLayout::RequireConsistentNewlines] +## +[CognitiveComplexity::ProhibitExcessCognitiveComplexity] + severity = 2 +## +[CompileTime] +## +[ControlStructures::ProhibitCascadingIfElse] + severity = 4 +## +[ControlStructures::ProhibitMutatingListFunctions] + list_funcs = grep List::Util::first +## +[ControlStructures::ProhibitPostfixControls] + allow = if unless + severity = cruel +## +[ErrorHandling::RequireCarping] + allow_messages_ending_with_newlines = 0 + allow_in_main_unless_in_subroutine = 1 + severity = 3 +## +[InputOutput::ProhibitBacktickOperators] +## +[InputOutput::ProhibitExplicitStdin] + severity = 5 +## +[InputOutput::RequireBriefOpen] + lines = 25 + severity = 5 +## +[Miscellanea::ProhibitUnrestrictedNoCritic] + severity = 4 +[Perlsecret] +## +[RegularExpressions::ProhibitCaptureWithoutTest] + severity = 5 +## +[RegularExpressions::ProhibitUnusedCapture] +## +[Subroutines::ProhibitBuiltinHomonyms] + severity = 5 +## +[Subroutines::ProhibitExcessComplexity] +## +### Moose +# Builders are pulled in from Moose, but perlcritic can't possibly begin +# to fathom that out. So let these things slide. +[Subroutines::ProhibitUnusedPrivateSubroutines] +private_name_regex = _(?!build)\w+ +## +[Subroutines::RequireArgUnpacking] + short_subroutine_statements = 2 + allow_subscripts = 1 + severity = 3 +## +[Subroutines::RequireFinalReturn] + severity = 5 +## +[TestingAndDebugging::RequireUseStrict] + equivalent_modules = MooseX::My::Sugar + severity = 5 +## +[TestingAndDebugging::RequireUseWarnings] + equivalent_modules = MooseX::My::Sugar + severity = 5 +## +## Modules that import strictures etc. +# We have use strict and use warnings, dammit. +# Adding Test::Class::Moose temporarily as perlcritic doesn't realise that, +# like Moose, it enables strictures and warnings. +[TestingAndDebugging::RequireUseStrict] +equivalent_modules = common::sense our::way Test::Class::Moose + +[TestingAndDebugging::RequireUseWarnings] +equivalent_modules = our::way Test::Class::Moose + +[TestingAndDebugging::ProhibitNoWarnings] + severity = 5 + allow = uninitialized once void experimental + +## +[TooMuchCode::ProhibitDuplicateLiteral] +# severity = 3 +## +[TooMuchCode::ProhibitLargeBlock] + severity = 5 +## +[TryTiny::ProhibitExitingSubroutine] + severity = 5 +## +[TooMuchCode::ProhibitUnnecessaryUTF8Pragma] + severity = 4 +[TryTiny::RequireCatch] +## +[Variables::ProhibitReusedNames] + severity = 5 +## +[Variables::ProhibitPunctuationVars] + allow = $@ $! +## +[Variables::RequireLocalizedPunctuationVars] + allow = %SIG +## +[ValuesAndExpressions::ProhibitMagicNumbers] + allowed_values = 0 1 2 +## +[ValuesAndExpressions::ProhibitLeadingZeros] + strict = 0 +## +[ValuesAndExpressions::RequireNumberSeparators] + min_value = 100000 + severity = brutal +## +[ValuesAndExpressions::RestrictLongStrings] + +# Yes, require /x but perhaps not for really trivial regexen +# or stuff that looks for a constant +[RegularExpressions::RequireExtendedFormatting] +minimum_regex_length_to_complain_about = 35 + +# Checking return values is a good thing. Checking the return value of +# close or print STDERR is downright silly, as is checking whether you +# managed to sleep or not (!). +[InputOutput::RequireCheckedSyscalls] +functions = :builtins +exclude_functions = print close sleep + +# Some things like DBIx::Class work fine with long chains of method calls. +# Bump up the number of method calls allowed. +[ValuesAndExpressions::ProhibitLongChainsOfMethodCalls] +max_chain_length = 5 + +# A blanket prohibition like this policy is harsh, but is meant as a +# building block or at least to make you think carefully whether "-f" is +# really right. +[-ValuesAndExpressions::ProhibitFiletest_f] + +## +[Variables::ProhibitLoopOnHash] +## +######################### should be rechecked soon ######################### +[-Subroutines::ProhibitSubroutinePrototypes] +[-ValuesAndExpressions::ProhibitConstantPragma] +[-Modules::ProhibitAutomaticExportation] + diff --git a/t/critic.t b/t/critic.t new file mode 100644 index 0000000..9ed61ce --- /dev/null +++ b/t/critic.t @@ -0,0 +1,6 @@ +use strict; +use warnings; +use Test::More; +plan skip_all => "Test::Perl::Critic required for testing filenames portability" + unless eval "use Test::Perl::Critic; 1"; +all_critic_ok("bin/"); \ No newline at end of file diff --git a/t/eol.t b/t/eol.t new file mode 100644 index 0000000..4b2992b --- /dev/null +++ b/t/eol.t @@ -0,0 +1,6 @@ +use strict; +use warnings; +use Test::More; +plan skip_all => "Test::EOL required for testing filenames portability" + unless eval "use Test::EOL; 1"; +all_perl_files_ok(); \ No newline at end of file -- GitLab