.perlcriticrc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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 say
  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. # tCMS:
  129. # generic_route, @routes, %aliases tPSGI reads them out of the router package
  130. # aliases (both models) TCMS::aliases calls $data->aliases, and
  131. # the policy takes a method call from a sub
  132. # of the same name for recursion
  133. # posts, order named by a post type's x-tcms-datasource
  134. # enrich named by a post type's sidecar
  135. # create_statement, log_message Log::Dispatch calls them
  136. # series, users a post's callback names them
  137. allow_subs = TCMS::generic_route Trog::Data::FlatFile::aliases Trog::DataModule::aliases Trog::DataSource::DirIndex::posts Trog::DataSource::DirIndex::order Trog::DataSource::ProvisionedVirt::posts Trog::Enrich::Invoice::enrich Trog::Log::DBI::create_statement Trog::Log::DBI::log_message Trog::Log::Syslog::log_message Trog::Routes::HTML::series Trog::Routes::HTML::users
  138. allow_globals = @TCMS::routes %TCMS::aliases
  139. # A sub that only one subclass uses, and a sub that two subclasses define where
  140. # the class above them defines none. It reads bin/ and lib/ through
  141. # Perl::Critic::Distribution, as ProhibitUnusedDefinitions does, so the two
  142. # share one parse. A library whose subclasses live in other distributions
  143. # names in allow_subs each hook that only one of its own subclasses uses.
  144. [ProhibitMisplacedMethods]
  145. [ProhibitPrintSTDERR]
  146. [InputOutput::ProhibitRepeatedPrints]
  147. # Perl::Critic's own policies. only = 1 loads nothing that is not named, so
  148. # each of these has to be, and the ones that are absent are absent on purpose.
  149. #
  150. # Not here, because something above already does the job better:
  151. # CodeLayout::ProhibitQuotedWordLists RequireQwForLiteralLists
  152. # ControlStructures::ProhibitCascadingIfElse CognitiveComplexity, which
  153. # ControlStructures::ProhibitDeepNests scores nesting and every
  154. # Subroutines::ProhibitExcessComplexity break in flow, where these
  155. # count branches
  156. # ControlStructures::ProhibitMutatingListFunctions
  157. # ProhibitMutatingListFunctionsStricter,
  158. # which reports all of it, and
  159. # a sub that the block calls
  160. # InputOutput::ProhibitBacktickOperators logicLAB::ProhibitShellDispatch
  161. # Modules::ProhibitEvilModules PreferredModules
  162. # Subroutines::ProhibitUnusedPrivateSubroutines ProhibitUnusedDefinitions,
  163. # which counts calls from bin/
  164. # and lib/, private or not
  165. # TestingAndDebugging::RequireUseWarnings RequireFatalWarnings
  166. # ValuesAndExpressions::ProhibitLeadingZeros Plicease::ProhibitLeadingZeros
  167. # Modules::RequireVersionVar [PkgVersion] in dist.ini
  168. # ErrorHandling::RequireCarping die with context, and
  169. # Carp::Always for the trace
  170. #
  171. # Nor the five the language enforces under this file's floor. The header says
  172. # which they are, and perlcriticrc.compat is where they live.
  173. #
  174. # Documentation::RequirePodSections is out as well: the sections it asks for are
  175. # the ones Pod::Weaver writes at build, and weaver.ini names them AUTHORS and
  176. # COPYRIGHT AND LICENSE where the policy wants AUTHOR and LICENSE AND COPYRIGHT.
  177. [BuiltinFunctions::ProhibitBooleanGrep]
  178. [BuiltinFunctions::ProhibitLvalueSubstr]
  179. [BuiltinFunctions::ProhibitReverseSortBlock]
  180. [BuiltinFunctions::ProhibitShiftRef]
  181. [BuiltinFunctions::ProhibitSleepViaSelect]
  182. [BuiltinFunctions::ProhibitStringyEval]
  183. [BuiltinFunctions::ProhibitStringySplit]
  184. [BuiltinFunctions::ProhibitUniversalCan]
  185. [BuiltinFunctions::ProhibitUniversalIsa]
  186. [BuiltinFunctions::ProhibitVoidGrep]
  187. [BuiltinFunctions::ProhibitVoidMap]
  188. [BuiltinFunctions::RequireBlockGrep]
  189. [BuiltinFunctions::RequireBlockMap]
  190. [BuiltinFunctions::RequireGlobFunction]
  191. [BuiltinFunctions::RequireSimpleSortBlock]
  192. [ClassHierarchies::ProhibitAutoloading]
  193. [ClassHierarchies::ProhibitExplicitISA]
  194. [ClassHierarchies::ProhibitOneArgBless]
  195. [CodeLayout::ProhibitHardTabs]
  196. [CodeLayout::ProhibitTrailingWhitespace]
  197. [CodeLayout::RequireConsistentNewlines]
  198. # [CodeLayout::RequireTidyCode] is off on purpose. git-hooks/pre-commit runs
  199. # perltidy over every staged Perl file before it runs this profile, so every
  200. # commit is tidy whatever this policy would say. In an editor, the policy only
  201. # repeated that, and ran perltidy over the whole file on every check.
  202. [CodeLayout::RequireTrailingCommas]
  203. [ControlStructures::ProhibitLabelsWithSpecialBlockNames]
  204. [ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions]
  205. [ControlStructures::ProhibitUnreachableCode]
  206. [ControlStructures::ProhibitUntilBlocks]
  207. [ControlStructures::ProhibitYadaOperator]
  208. [Documentation::PodSpelling]
  209. spell_command = aspell --lang=en_US list
  210. stop_words_file = .pod_stopwords
  211. [Documentation::RequirePackageMatchesPodName]
  212. [ErrorHandling::RequireCheckingReturnValueOfEval]
  213. [InputOutput::ProhibitExplicitStdin]
  214. [InputOutput::ProhibitInteractiveTest]
  215. [InputOutput::ProhibitJoinedReadline]
  216. [InputOutput::ProhibitOneArgSelect]
  217. [InputOutput::ProhibitReadlineInForLoop]
  218. [InputOutput::ProhibitTwoArgOpen]
  219. [InputOutput::RequireBracedFileHandleWithPrint]
  220. [InputOutput::RequireBriefOpen]
  221. [InputOutput::RequireCheckedOpen]
  222. [InputOutput::RequireCheckedSyscalls]
  223. # tCMS: say prints as print does.
  224. exclude_functions = print say
  225. [InputOutput::RequireEncodingWithUTF8Layer]
  226. [Miscellanea::ProhibitFormats]
  227. [Miscellanea::ProhibitTies]
  228. [Miscellanea::ProhibitUnrestrictedNoCritic]
  229. #[Miscellanea::ProhibitUselessNoCritic]
  230. [Modules::ProhibitAutomaticExportation]
  231. [Modules::ProhibitConditionalUseStatements]
  232. [Modules::RequireBarewordIncludes]
  233. [Modules::RequireFilenameMatchesPackage]
  234. [Modules::RequireNoMatchVarsWithUseEnglish]
  235. [NamingConventions::Capitalization]
  236. # tCMS: each renderer is named for the content type it renders, and each
  237. # script's package for the script. The policy tests each part of a package
  238. # name on its own, so these are the parts.
  239. package_exemptions = main tcms login useradd blob css email html json text
  240. [RegularExpressions::ProhibitCaptureWithoutTest]
  241. [RegularExpressions::ProhibitComplexRegexes]
  242. [RegularExpressions::ProhibitEnumeratedClasses]
  243. [RegularExpressions::ProhibitFixedStringMatches]
  244. [RegularExpressions::ProhibitSingleCharAlternation]
  245. [RegularExpressions::ProhibitUnusedCapture]
  246. [RegularExpressions::RequireBracesForMultiline]
  247. [RegularExpressions::RequireDotMatchAnything]
  248. [RegularExpressions::RequireExtendedFormatting]
  249. [Subroutines::ProhibitAmpersandSigils]
  250. [Subroutines::ProhibitBuiltinHomonyms]
  251. # tCMS: read, write and delete are methods of every data model. index is the
  252. # route that every page ends in, which a theme's routes call by that name.
  253. # shutdown is a method of Sys::Virt::Domain, which a test fakes.
  254. allow = read write delete index shutdown
  255. [Subroutines::ProhibitManyArgs]
  256. [Subroutines::ProhibitNestedSubs]
  257. [Subroutines::ProhibitReturnSort]
  258. [Subroutines::ProhibitSubroutinePrototypes]
  259. [Subroutines::ProtectPrivateSubs]
  260. [Subroutines::RequireArgUnpacking]
  261. [Subroutines::RequireFinalReturn]
  262. # tCMS: a sub that forks ends its child with POSIX::_exit, which never returns.
  263. terminal_funcs = POSIX::_exit
  264. [TestingAndDebugging::ProhibitProlongedStrictureOverride]
  265. [TestingAndDebugging::RequireTestLabels]
  266. [ValuesAndExpressions::ProhibitCommaSeparatedStatements]
  267. [ValuesAndExpressions::ProhibitComplexVersion]
  268. [ValuesAndExpressions::ProhibitEscapedCharacters]
  269. [ValuesAndExpressions::ProhibitLongChainsOfMethodCalls]
  270. [ValuesAndExpressions::ProhibitMismatchedOperators]
  271. [ValuesAndExpressions::ProhibitMixedBooleanOperators]
  272. [ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters]
  273. [ValuesAndExpressions::ProhibitSpecialLiteralHeredocTerminator]
  274. [ValuesAndExpressions::ProhibitVersionStrings]
  275. [ValuesAndExpressions::RequireConstantVersion]
  276. [ValuesAndExpressions::RequireQuotedHeredocTerminator]
  277. [ValuesAndExpressions::RequireUpperCaseHeredocTerminator]
  278. [Variables::ProhibitAugmentedAssignmentInDeclaration]
  279. [Variables::ProhibitConditionalDeclarations]
  280. # Variables::ProhibitEvilVariables is not listed: it declines to load until it
  281. # is given variables to prohibit, and nobody has named any.
  282. [Variables::ProhibitLocalVars]
  283. [Variables::ProhibitMatchVars]
  284. # Drop this one at 5.041 and later, with RequireASCII above.
  285. [Variables::ProhibitPerl4PackageNames]
  286. [Variables::ProhibitReusedNames]
  287. # Stricter than the core ProhibitUnusedVariables, which reports only a bare
  288. # `my $x;` and misses a variable that is assigned and never read.
  289. [Variables::ProhibitUnusedVarsStricter]
  290. # A method takes the arguments of its interface, whether it reads them or not.
  291. allow_unused_subroutine_arguments = 1
  292. # Anything that returns a guard, which does its work by being held to the end of
  293. # its scope: a mock, a mocked file, a change of directory, a lock.
  294. # allow_if_computed_by = Test::MockModule->new Test::MockFile->file
  295. [Variables::ProtectPrivateVars]
  296. [Variables::RequireLexicalLoopIterators]
  297. #[Variables::RequireLocalizedPunctuationVars]
  298. [Variables::RequireNegativeIndices]
  299. # Extensions to perl -c
  300. #[CompileTime]