.perlcriticrc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. # Troglodyne perlcritic policy, for a distribution that declares use 5.040 or
  2. # later.
  3. #
  4. # There are two of these. This one is for code that runs on a perl you control,
  5. # and perlcriticrc.compat is for code that runs on whatever perl is already
  6. # installed. The packaging-perl skill asks which you are writing before it
  7. # copies one, because the answer decides more than this file: it decides the
  8. # use line in every module and test, and perl: in prereqs.yml.
  9. #
  10. # The difference between the two is five policies. A modern perl refuses what
  11. # they report, so naming them here would buy nothing:
  12. #
  13. # TestingAndDebugging::RequireUseStrict strict is on from 5.012
  14. # Objects::ProhibitIndirectSyntax no indirect from 5.036
  15. # InputOutput::ProhibitBarewordFileHandles no bareword_filehandles from
  16. # InputOutput::ProhibitBarewordDirHandles 5.038
  17. # Modules::RequireEndWithOne module_true from 5.038
  18. #
  19. # Two more go the same way at 5.042, and are named below because this file
  20. # assumes only 5.040. Delete them once your floor is 5.041 or later, which
  21. # selects the 5.042 bundle:
  22. #
  23. # Variables::ProhibitPerl4PackageNames no apostrophe as a package
  24. # separator from 5.042
  25. # CodeLayout::RequireASCII source::encoding "ascii" from
  26. # 5.042, which is stricter than
  27. # the policy and not skippable
  28. #
  29. # tCMS: a policy commented out as #[Name], with no space, is one that the tree
  30. # does not pass yet. The change that fixes the tree for it enables it.
  31. severity = 1
  32. only = 1
  33. force = 0
  34. verbose = 1
  35. criticism-fatal = 1
  36. color = 1
  37. allow-unsafe = 1
  38. # Usability
  39. [Modules::RequirePerlVersion]
  40. [Documentation::RequirePod]
  41. # Security
  42. [ValuesAndExpressions::PreventSQLInjection]
  43. # Drop this one at 5.041 and later. It also applies to POD, where the only
  44. # thing it tends to catch is a contributor's name in the section Dist::Zilla
  45. # generates, and spelling somebody's name wrong is not a code standard.
  46. [CodeLayout::RequireASCII]
  47. [RegularExpressions::RequireDefault]
  48. strict = 1
  49. [RegularExpressions::PreventUselessMetacharacterEscapes]
  50. # PEBCAK catches
  51. [BuiltinFunctions::ProhibitDeleteOnArrays]
  52. [Subroutines::ProhibitAmbiguousFunctionCalls]
  53. [ValuesAndExpressions::ProhibitSingleArgArraySlice]
  54. [ValuesAndExpressions::ProhibitDefinedBeforeLength]
  55. [Variables::ProhibitUselessVarClearing]
  56. [Subroutines::ProhibitTailRecursion]
  57. [Bangs::ProhibitUselessRegexModifiers]
  58. [Bangs::ProhibitCommentedOutCode]
  59. [Tics::ProhibitUseBase]
  60. [Plicease::ProhibitLeadingZeros]
  61. [RegularExpressions::ProhibitEmptyAlternatives]
  62. [ValuesAndExpressions::UnexpandedSpecialLiteral]
  63. [CodeLayout::ProhibitIfIfSameLine]
  64. [ValuesAndExpressions::ConstantBeforeLt]
  65. [ValuesAndExpressions::ProhibitDuplicateHashKeys]
  66. # any access checks are necessarily a TOCTOU waiting to happen
  67. #[ValuesAndExpressions::ProhibitFiletest_f]
  68. [ValuesAndExpressions::ProhibitFiletest_rwxRWX]
  69. # Bikeshed
  70. [CognitiveComplexity::ProhibitExcessCognitiveComplexity]
  71. warn_level = 40
  72. info_level = 30
  73. [Variables::ProhibitUselessInitialization]
  74. [PreferredModules]
  75. config = .preferred_modules.ini
  76. [logicLAB::RequireSheBang]
  77. formats = #!/usr/bin/env perl
  78. # Performance
  79. [logicLAB::ProhibitShellDispatch]
  80. [ProhibitPipeOpen]
  81. #[Performance::ProhibitRegexForSimpleSubstring]
  82. [RegularExpressions::ProhibitRegexToStripAffix]
  83. [RegularExpressions::ProhibitRegexToChomp]
  84. [BuiltinFunctions::ProhibitChainingSameListSub]
  85. [RegularExpressions::ProhibitRegexForStringEquality]
  86. [Subroutines::ProhibitUnderscorePrivateSubs]
  87. #[Subroutines::ProhibitSingleUseLexicalSubs]
  88. [ValuesAndExpressions::ProhibitLiteralArithmetic]
  89. [BuiltinFunctions::ProhibitIndirectBooleanGrep]
  90. # What ProhibitMutatingListFunctions reports, which this replaces, and a block
  91. # that changes $_ through a sub that it calls.
  92. [ControlStructures::ProhibitMutatingListFunctionsStricter]
  93. # An if, elsif, else or unless whose block holds no statement, a comment
  94. # being none. Loops are left alone, because a loop condition can do the work.
  95. [ControlStructures::ProhibitEmptyConditionalBlocks]
  96. # A sub that returns the result of a syscall or an eval, called where nothing
  97. # looks at the result. The same functions as RequireCheckedSyscalls below.
  98. [ErrorHandling::RequireCheckedIndirectResults]
  99. exclude_functions = print
  100. [ProhibitUseLib]
  101. #[ProhibitUsageSubs]
  102. [RequireQwForLiteralLists]
  103. [ProhibitNoWarningsRedefine]
  104. [RequireFatalWarnings]
  105. [ProhibitUnusedImports]
  106. # Modules imported for a side effect rather than for a symbol, which the policy
  107. # cannot see. `re` is here because every file says `use re '/aa'`. Add your
  108. # own: IO::Prompter installs prompt() from a custom import rather than @EXPORT,
  109. # and anything loaded by name from a string is invisible the same way.
  110. # tCMS: Exporter, because use Exporter 'import' imports the method that perl
  111. # calls, which no line of the module names.
  112. allow = re Exporter
  113. # Off in a distribution that is only a library: it counts calls from bin/ and
  114. # lib/, and every sub a library exists to offer is called from neither -- a
  115. # module with one public sub and no bin/ reports that sub, which is the policy
  116. # working correctly and saying nothing. Turn it on for a distribution that also
  117. # ships programs, and add the authordep line to dist.ini when you do.
  118. #
  119. # allow_subs then lists the subs that are called in a way it cannot see: named
  120. # in a string and called as $obj->$name, handed to something else that calls
  121. # them, or called only from a directory it does not read. Name each one and say
  122. # which, so the next person can tell an exemption from an oversight.
  123. #
  124. #[ProhibitUnusedDefinitions]
  125. #allow_subs =
  126. # A sub that only one subclass uses, and a sub that two subclasses define where
  127. # the class above them defines none. It reads bin/ and lib/ through
  128. # Perl::Critic::Distribution, as ProhibitUnusedDefinitions does, so the two
  129. # share one parse. A library whose subclasses live in other distributions
  130. # names in allow_subs each hook that only one of its own subclasses uses.
  131. #[ProhibitMisplacedMethods]
  132. #[ProhibitPrintSTDERR]
  133. #[InputOutput::ProhibitRepeatedPrints]
  134. # Perl::Critic's own policies. only = 1 loads nothing that is not named, so
  135. # each of these has to be, and the ones that are absent are absent on purpose.
  136. #
  137. # Not here, because something above already does the job better:
  138. # CodeLayout::ProhibitQuotedWordLists RequireQwForLiteralLists
  139. # ControlStructures::ProhibitCascadingIfElse CognitiveComplexity, which
  140. # ControlStructures::ProhibitDeepNests scores nesting and every
  141. # Subroutines::ProhibitExcessComplexity break in flow, where these
  142. # count branches
  143. # ControlStructures::ProhibitMutatingListFunctions
  144. # ProhibitMutatingListFunctionsStricter,
  145. # which reports all of it, and
  146. # a sub that the block calls
  147. # InputOutput::ProhibitBacktickOperators logicLAB::ProhibitShellDispatch
  148. # Modules::ProhibitEvilModules PreferredModules
  149. # Subroutines::ProhibitUnusedPrivateSubroutines ProhibitUnusedDefinitions,
  150. # which counts calls from bin/
  151. # and lib/, private or not
  152. # TestingAndDebugging::RequireUseWarnings RequireFatalWarnings
  153. # ValuesAndExpressions::ProhibitLeadingZeros Plicease::ProhibitLeadingZeros
  154. # Modules::RequireVersionVar [PkgVersion] in dist.ini
  155. # ErrorHandling::RequireCarping die with context, and
  156. # Carp::Always for the trace
  157. #
  158. # Nor the five the language enforces under this file's floor. The header says
  159. # which they are, and perlcriticrc.compat is where they live.
  160. #
  161. # Documentation::RequirePodSections is out as well: the sections it asks for are
  162. # the ones Pod::Weaver writes at build, and weaver.ini names them AUTHORS and
  163. # COPYRIGHT AND LICENSE where the policy wants AUTHOR and LICENSE AND COPYRIGHT.
  164. #[BuiltinFunctions::ProhibitBooleanGrep]
  165. [BuiltinFunctions::ProhibitLvalueSubstr]
  166. #[BuiltinFunctions::ProhibitReverseSortBlock]
  167. [BuiltinFunctions::ProhibitShiftRef]
  168. [BuiltinFunctions::ProhibitSleepViaSelect]
  169. [BuiltinFunctions::ProhibitStringyEval]
  170. #[BuiltinFunctions::ProhibitStringySplit]
  171. [BuiltinFunctions::ProhibitUniversalCan]
  172. [BuiltinFunctions::ProhibitUniversalIsa]
  173. [BuiltinFunctions::ProhibitVoidGrep]
  174. [BuiltinFunctions::ProhibitVoidMap]
  175. [BuiltinFunctions::RequireBlockGrep]
  176. [BuiltinFunctions::RequireBlockMap]
  177. [BuiltinFunctions::RequireGlobFunction]
  178. [BuiltinFunctions::RequireSimpleSortBlock]
  179. [ClassHierarchies::ProhibitAutoloading]
  180. [ClassHierarchies::ProhibitExplicitISA]
  181. [ClassHierarchies::ProhibitOneArgBless]
  182. [CodeLayout::ProhibitHardTabs]
  183. [CodeLayout::ProhibitTrailingWhitespace]
  184. [CodeLayout::RequireConsistentNewlines]
  185. # [CodeLayout::RequireTidyCode] is off on purpose. git-hooks/pre-commit runs
  186. # perltidy over every staged Perl file before it runs this profile, so every
  187. # commit is tidy whatever this policy would say. In an editor, the policy only
  188. # repeated that, and ran perltidy over the whole file on every check.
  189. [CodeLayout::RequireTrailingCommas]
  190. [ControlStructures::ProhibitLabelsWithSpecialBlockNames]
  191. #[ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions]
  192. [ControlStructures::ProhibitUnreachableCode]
  193. [ControlStructures::ProhibitUntilBlocks]
  194. #[ControlStructures::ProhibitYadaOperator]
  195. #[Documentation::PodSpelling]
  196. #spell_command = aspell --lang=en_US list
  197. #stop_words_file = .pod_stopwords
  198. [Documentation::RequirePackageMatchesPodName]
  199. #[ErrorHandling::RequireCheckingReturnValueOfEval]
  200. [InputOutput::ProhibitExplicitStdin]
  201. [InputOutput::ProhibitInteractiveTest]
  202. [InputOutput::ProhibitJoinedReadline]
  203. [InputOutput::ProhibitOneArgSelect]
  204. [InputOutput::ProhibitReadlineInForLoop]
  205. [InputOutput::ProhibitTwoArgOpen]
  206. #[InputOutput::RequireBracedFileHandleWithPrint]
  207. #[InputOutput::RequireBriefOpen]
  208. [InputOutput::RequireCheckedOpen]
  209. #[InputOutput::RequireCheckedSyscalls]
  210. #exclude_functions = print
  211. [InputOutput::RequireEncodingWithUTF8Layer]
  212. [Miscellanea::ProhibitFormats]
  213. [Miscellanea::ProhibitTies]
  214. [Miscellanea::ProhibitUnrestrictedNoCritic]
  215. #[Miscellanea::ProhibitUselessNoCritic]
  216. [Modules::ProhibitAutomaticExportation]
  217. #[Modules::ProhibitConditionalUseStatements]
  218. [Modules::RequireBarewordIncludes]
  219. [Modules::RequireFilenameMatchesPackage]
  220. [Modules::RequireNoMatchVarsWithUseEnglish]
  221. #[NamingConventions::Capitalization]
  222. [RegularExpressions::ProhibitCaptureWithoutTest]
  223. #[RegularExpressions::ProhibitComplexRegexes]
  224. #[RegularExpressions::ProhibitEnumeratedClasses]
  225. [RegularExpressions::ProhibitFixedStringMatches]
  226. [RegularExpressions::ProhibitSingleCharAlternation]
  227. [RegularExpressions::ProhibitUnusedCapture]
  228. [RegularExpressions::RequireBracesForMultiline]
  229. [RegularExpressions::RequireDotMatchAnything]
  230. [RegularExpressions::RequireExtendedFormatting]
  231. [Subroutines::ProhibitAmpersandSigils]
  232. #[Subroutines::ProhibitBuiltinHomonyms]
  233. [Subroutines::ProhibitManyArgs]
  234. [Subroutines::ProhibitNestedSubs]
  235. [Subroutines::ProhibitReturnSort]
  236. [Subroutines::ProhibitSubroutinePrototypes]
  237. [Subroutines::ProtectPrivateSubs]
  238. #[Subroutines::RequireArgUnpacking]
  239. [Subroutines::RequireFinalReturn]
  240. # tCMS: a sub that forks ends its child with POSIX::_exit, which never returns.
  241. terminal_funcs = POSIX::_exit
  242. [TestingAndDebugging::ProhibitProlongedStrictureOverride]
  243. [TestingAndDebugging::RequireTestLabels]
  244. #[ValuesAndExpressions::ProhibitCommaSeparatedStatements]
  245. [ValuesAndExpressions::ProhibitComplexVersion]
  246. [ValuesAndExpressions::ProhibitEscapedCharacters]
  247. [ValuesAndExpressions::ProhibitLongChainsOfMethodCalls]
  248. [ValuesAndExpressions::ProhibitMismatchedOperators]
  249. [ValuesAndExpressions::ProhibitMixedBooleanOperators]
  250. [ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters]
  251. [ValuesAndExpressions::ProhibitSpecialLiteralHeredocTerminator]
  252. [ValuesAndExpressions::ProhibitVersionStrings]
  253. [ValuesAndExpressions::RequireConstantVersion]
  254. [ValuesAndExpressions::RequireQuotedHeredocTerminator]
  255. [ValuesAndExpressions::RequireUpperCaseHeredocTerminator]
  256. [Variables::ProhibitAugmentedAssignmentInDeclaration]
  257. [Variables::ProhibitConditionalDeclarations]
  258. # Variables::ProhibitEvilVariables is not listed: it declines to load until it
  259. # is given variables to prohibit, and nobody has named any.
  260. [Variables::ProhibitLocalVars]
  261. [Variables::ProhibitMatchVars]
  262. # Drop this one at 5.041 and later, with RequireASCII above.
  263. [Variables::ProhibitPerl4PackageNames]
  264. [Variables::ProhibitReusedNames]
  265. # Stricter than the core ProhibitUnusedVariables, which reports only a bare
  266. # `my $x;` and misses a variable that is assigned and never read.
  267. [Variables::ProhibitUnusedVarsStricter]
  268. # A method takes the arguments of its interface, whether it reads them or not.
  269. allow_unused_subroutine_arguments = 1
  270. # Anything that returns a guard, which does its work by being held to the end of
  271. # its scope: a mock, a mocked file, a change of directory, a lock.
  272. # allow_if_computed_by = Test::MockModule->new Test::MockFile->file
  273. [Variables::ProtectPrivateVars]
  274. [Variables::RequireLexicalLoopIterators]
  275. #[Variables::RequireLocalizedPunctuationVars]
  276. [Variables::RequireNegativeIndices]
  277. # Extensions to perl -c
  278. #[CompileTime]