Bladeren bron

Enable RequireLocalizedPunctuationVars, except for tests

A change to %ENV, %INC or a punctuation variable inside a sub outlives
the sub unless it is local, and nothing in bin/ or lib/ does that now.
A test is the other case: it sets HOME, the vault key and %INC for its
inline fixture packages in a BEGIN block, before the SUT loads, and
means them for the whole file.  A local there would end with the BEGIN
block.  So the hook leaves this policy out for t/, as it does RequirePod.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
troglodyne-bot 1 week geleden
bovenliggende
commit
adf4e5e2ef
2 gewijzigde bestanden met toevoegingen van 8 en 6 verwijderingen
  1. 1 1
      .perlcriticrc
  2. 7 5
      git-hooks/pre-commit

+ 1 - 1
.perlcriticrc

@@ -294,7 +294,7 @@ allow_unused_subroutine_arguments = 1
 # allow_if_computed_by = Test::MockModule->new Test::MockFile->file
 [Variables::ProtectPrivateVars]
 [Variables::RequireLexicalLoopIterators]
-#[Variables::RequireLocalizedPunctuationVars]
+[Variables::RequireLocalizedPunctuationVars]
 [Variables::RequireNegativeIndices]
 # Extensions to perl -c
 #[CompileTime]

+ 7 - 5
git-hooks/pre-commit

@@ -130,14 +130,16 @@ then
         perlcritic --profile .perlcriticrc $lib_files || critic_failed=1
     fi
 
-    # The same profile for t/, less one policy.  A test is not a module: nobody
+    # The same profile for t/, less two policies.  A test is not a module: nobody
     # runs perldoc on it, so requiring POD of it asks for a page no reader will
-    # ever open.  Everything else in the profile still judges it, which is more
-    # than a release does -- all_critic_ok() reads lib/ and not t/, so this hook
-    # is the only thing that looks at a test file at all.
+    # ever open.  And a test sets %ENV and %INC for the whole file, in a BEGIN
+    # block before the SUT loads, where a local would end with the block.
+    # Everything else in the profile still judges it, which is more than a
+    # release does -- all_critic_ok() reads lib/ and not t/, so this hook is the
+    # only thing that looks at a test file at all.
     if [ -n "$test_files" ]
     then
-        perlcritic --profile .perlcriticrc --exclude Documentation::RequirePod $test_files || critic_failed=1
+        perlcritic --profile .perlcriticrc --exclude Documentation::RequirePod --exclude Variables::RequireLocalizedPunctuationVars $test_files || critic_failed=1
     fi
 
     if [ -n "$critic_failed" ]