.perlcriticrc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. # tCMS: help() is the interface of a data model and a datasource that links
  103. # the documentation of its query language, so it is not a usage message.
  104. sub_names = usage _usage print_usage usage_message
  105. [RequireQwForLiteralLists]
  106. [ProhibitNoWarningsRedefine]
  107. [RequireFatalWarnings]
  108. [ProhibitUnusedImports]
  109. # Modules imported for a side effect rather than for a symbol, which the policy
  110. # cannot see. `re` is here because every file says `use re '/aa'`. Add your
  111. # own: IO::Prompter installs prompt() from a custom import rather than @EXPORT,
  112. # and anything loaded by name from a string is invisible the same way.
  113. # tCMS: Exporter, because use Exporter 'import' imports the method that perl
  114. # calls, which no line of the module names.
  115. allow = re Exporter
  116. # Off in a distribution that is only a library: it counts calls from bin/ and
  117. # lib/, and every sub a library exists to offer is called from neither -- a
  118. # module with one public sub and no bin/ reports that sub, which is the policy
  119. # working correctly and saying nothing. Turn it on for a distribution that also
  120. # ships programs, and add the authordep line to dist.ini when you do.
  121. #
  122. # allow_subs then lists the subs that are called in a way it cannot see: named
  123. # in a string and called as $obj->$name, handed to something else that calls
  124. # them, or called only from a directory it does not read. Name each one and say
  125. # which, so the next person can tell an exemption from an oversight.
  126. #
  127. #[ProhibitUnusedDefinitions]
  128. #allow_subs =
  129. # A sub that only one subclass uses, and a sub that two subclasses define where
  130. # the class above them defines none. It reads bin/ and lib/ through
  131. # Perl::Critic::Distribution, as ProhibitUnusedDefinitions does, so the two
  132. # share one parse. A library whose subclasses live in other distributions
  133. # names in allow_subs each hook that only one of its own subclasses uses.
  134. [ProhibitMisplacedMethods]
  135. [ProhibitPrintSTDERR]
  136. [InputOutput::ProhibitRepeatedPrints]
  137. # Perl::Critic's own policies. only = 1 loads nothing that is not named, so
  138. # each of these has to be, and the ones that are absent are absent on purpose.
  139. #
  140. # Not here, because something above already does the job better:
  141. # CodeLayout::ProhibitQuotedWordLists RequireQwForLiteralLists
  142. # ControlStructures::ProhibitCascadingIfElse CognitiveComplexity, which
  143. # ControlStructures::ProhibitDeepNests scores nesting and every
  144. # Subroutines::ProhibitExcessComplexity break in flow, where these
  145. # count branches
  146. # ControlStructures::ProhibitMutatingListFunctions
  147. # ProhibitMutatingListFunctionsStricter,
  148. # which reports all of it, and
  149. # a sub that the block calls
  150. # InputOutput::ProhibitBacktickOperators logicLAB::ProhibitShellDispatch
  151. # Modules::ProhibitEvilModules PreferredModules
  152. # Subroutines::ProhibitUnusedPrivateSubroutines ProhibitUnusedDefinitions,
  153. # which counts calls from bin/
  154. # and lib/, private or not
  155. # TestingAndDebugging::RequireUseWarnings RequireFatalWarnings
  156. # ValuesAndExpressions::ProhibitLeadingZeros Plicease::ProhibitLeadingZeros
  157. # Modules::RequireVersionVar [PkgVersion] in dist.ini
  158. # ErrorHandling::RequireCarping die with context, and
  159. # Carp::Always for the trace
  160. #
  161. # Nor the five the language enforces under this file's floor. The header says
  162. # which they are, and perlcriticrc.compat is where they live.
  163. #
  164. # Documentation::RequirePodSections is out as well: the sections it asks for are
  165. # the ones Pod::Weaver writes at build, and weaver.ini names them AUTHORS and
  166. # COPYRIGHT AND LICENSE where the policy wants AUTHOR and LICENSE AND COPYRIGHT.
  167. [BuiltinFunctions::ProhibitBooleanGrep]
  168. [BuiltinFunctions::ProhibitLvalueSubstr]
  169. [BuiltinFunctions::ProhibitReverseSortBlock]
  170. [BuiltinFunctions::ProhibitShiftRef]
  171. [BuiltinFunctions::ProhibitSleepViaSelect]
  172. [BuiltinFunctions::ProhibitStringyEval]
  173. [BuiltinFunctions::ProhibitStringySplit]
  174. [BuiltinFunctions::ProhibitUniversalCan]
  175. [BuiltinFunctions::ProhibitUniversalIsa]
  176. [BuiltinFunctions::ProhibitVoidGrep]
  177. [BuiltinFunctions::ProhibitVoidMap]
  178. [BuiltinFunctions::RequireBlockGrep]
  179. [BuiltinFunctions::RequireBlockMap]
  180. [BuiltinFunctions::RequireGlobFunction]
  181. [BuiltinFunctions::RequireSimpleSortBlock]
  182. [ClassHierarchies::ProhibitAutoloading]
  183. [ClassHierarchies::ProhibitExplicitISA]
  184. [ClassHierarchies::ProhibitOneArgBless]
  185. [CodeLayout::ProhibitHardTabs]
  186. [CodeLayout::ProhibitTrailingWhitespace]
  187. [CodeLayout::RequireConsistentNewlines]
  188. # [CodeLayout::RequireTidyCode] is off on purpose. git-hooks/pre-commit runs
  189. # perltidy over every staged Perl file before it runs this profile, so every
  190. # commit is tidy whatever this policy would say. In an editor, the policy only
  191. # repeated that, and ran perltidy over the whole file on every check.
  192. [CodeLayout::RequireTrailingCommas]
  193. [ControlStructures::ProhibitLabelsWithSpecialBlockNames]
  194. [ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions]
  195. [ControlStructures::ProhibitUnreachableCode]
  196. [ControlStructures::ProhibitUntilBlocks]
  197. [ControlStructures::ProhibitYadaOperator]
  198. [Documentation::PodSpelling]
  199. spell_command = aspell --lang=en_US list
  200. stop_words_file = .pod_stopwords
  201. [Documentation::RequirePackageMatchesPodName]
  202. [ErrorHandling::RequireCheckingReturnValueOfEval]
  203. [InputOutput::ProhibitExplicitStdin]
  204. [InputOutput::ProhibitInteractiveTest]
  205. [InputOutput::ProhibitJoinedReadline]
  206. [InputOutput::ProhibitOneArgSelect]
  207. [InputOutput::ProhibitReadlineInForLoop]
  208. [InputOutput::ProhibitTwoArgOpen]
  209. [InputOutput::RequireBracedFileHandleWithPrint]
  210. [InputOutput::RequireBriefOpen]
  211. [InputOutput::RequireCheckedOpen]
  212. #[InputOutput::RequireCheckedSyscalls]
  213. #exclude_functions = print
  214. [InputOutput::RequireEncodingWithUTF8Layer]
  215. [Miscellanea::ProhibitFormats]
  216. [Miscellanea::ProhibitTies]
  217. [Miscellanea::ProhibitUnrestrictedNoCritic]
  218. #[Miscellanea::ProhibitUselessNoCritic]
  219. [Modules::ProhibitAutomaticExportation]
  220. [Modules::ProhibitConditionalUseStatements]
  221. [Modules::RequireBarewordIncludes]
  222. [Modules::RequireFilenameMatchesPackage]
  223. [Modules::RequireNoMatchVarsWithUseEnglish]
  224. [NamingConventions::Capitalization]
  225. # tCMS: each renderer is named for the content type it renders, and each
  226. # script's package for the script. The policy tests each part of a package
  227. # name on its own, so these are the parts.
  228. package_exemptions = main tcms login useradd blob css email html javascript json text
  229. [RegularExpressions::ProhibitCaptureWithoutTest]
  230. #[RegularExpressions::ProhibitComplexRegexes]
  231. [RegularExpressions::ProhibitEnumeratedClasses]
  232. [RegularExpressions::ProhibitFixedStringMatches]
  233. [RegularExpressions::ProhibitSingleCharAlternation]
  234. [RegularExpressions::ProhibitUnusedCapture]
  235. [RegularExpressions::RequireBracesForMultiline]
  236. [RegularExpressions::RequireDotMatchAnything]
  237. [RegularExpressions::RequireExtendedFormatting]
  238. [Subroutines::ProhibitAmpersandSigils]
  239. #[Subroutines::ProhibitBuiltinHomonyms]
  240. [Subroutines::ProhibitManyArgs]
  241. [Subroutines::ProhibitNestedSubs]
  242. [Subroutines::ProhibitReturnSort]
  243. [Subroutines::ProhibitSubroutinePrototypes]
  244. [Subroutines::ProtectPrivateSubs]
  245. #[Subroutines::RequireArgUnpacking]
  246. [Subroutines::RequireFinalReturn]
  247. # tCMS: a sub that forks ends its child with POSIX::_exit, which never returns.
  248. terminal_funcs = POSIX::_exit
  249. [TestingAndDebugging::ProhibitProlongedStrictureOverride]
  250. [TestingAndDebugging::RequireTestLabels]
  251. [ValuesAndExpressions::ProhibitCommaSeparatedStatements]
  252. [ValuesAndExpressions::ProhibitComplexVersion]
  253. [ValuesAndExpressions::ProhibitEscapedCharacters]
  254. [ValuesAndExpressions::ProhibitLongChainsOfMethodCalls]
  255. [ValuesAndExpressions::ProhibitMismatchedOperators]
  256. [ValuesAndExpressions::ProhibitMixedBooleanOperators]
  257. [ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters]
  258. [ValuesAndExpressions::ProhibitSpecialLiteralHeredocTerminator]
  259. [ValuesAndExpressions::ProhibitVersionStrings]
  260. [ValuesAndExpressions::RequireConstantVersion]
  261. [ValuesAndExpressions::RequireQuotedHeredocTerminator]
  262. [ValuesAndExpressions::RequireUpperCaseHeredocTerminator]
  263. [Variables::ProhibitAugmentedAssignmentInDeclaration]
  264. [Variables::ProhibitConditionalDeclarations]
  265. # Variables::ProhibitEvilVariables is not listed: it declines to load until it
  266. # is given variables to prohibit, and nobody has named any.
  267. [Variables::ProhibitLocalVars]
  268. [Variables::ProhibitMatchVars]
  269. # Drop this one at 5.041 and later, with RequireASCII above.
  270. [Variables::ProhibitPerl4PackageNames]
  271. [Variables::ProhibitReusedNames]
  272. # Stricter than the core ProhibitUnusedVariables, which reports only a bare
  273. # `my $x;` and misses a variable that is assigned and never read.
  274. [Variables::ProhibitUnusedVarsStricter]
  275. # A method takes the arguments of its interface, whether it reads them or not.
  276. allow_unused_subroutine_arguments = 1
  277. # Anything that returns a guard, which does its work by being held to the end of
  278. # its scope: a mock, a mocked file, a change of directory, a lock.
  279. # allow_if_computed_by = Test::MockModule->new Test::MockFile->file
  280. [Variables::ProtectPrivateVars]
  281. [Variables::RequireLexicalLoopIterators]
  282. #[Variables::RequireLocalizedPunctuationVars]
  283. [Variables::RequireNegativeIndices]
  284. # Extensions to perl -c
  285. #[CompileTime]