nysus has asked for the wisdom of the Perl Monks concerning the following question:

I'm using Import::Base to generate boilerplate for my tests:

package Test::Utils; use parent 'Import::Base'; our @IMPORT_MODULES = ( 'strict', 'warnings', feature => [qw(:5.14)], 'Data::Dumper' => [qw(Dumper)], 'Test::More', 'Test::Exception', 'Test::Output', 'Test::Dirs', 'Test::Utils::Dump' => [qw(d d0 d1 $doff)], 'Term::ANSIColor', );

At the top of my test file, I have use Test::Utils and so strict is in effect. However, since perlcritic doesn't compile all the code, it's throwing warnings at me about not using strict. I tried to quiet the warnings in a .perlcriticrc file in my t directory:

severity = 5 [-TestingAndDebugging::RequireUseStrict]

But in nvim, I'm still seeing "S>" in a red background and when I put my cursor on the first line of code, the status line is showing this warning: "(5) Code before strictures are enabled (See page 429 of PBP)". Anything else I can do to suppress this warning?

UPDATE: I thought I found a solution using equivalent_modules=Test::Utils but it had no effect.

$PM = "Perl Monk's";
$MC = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar Parson";
$nysus = $PM . ' ' . $MC;
Click here if you love Perl Monks

  • Comment on SOLVED: Can't figure out how to quiet perlcritic and ignore RequireUseStrict perlcritic rule
  • Select or Download Code

Replies are listed 'Best First'.
Re: Can't figure out how to quiet perlcritic and ignore RequireUseStrict perlcritic rule
by hippo (Archbishop) on Jan 15, 2024 at 16:30 UTC

    perlcritic --exclude RequireUseStrict foo.pm works for me. Are you sure that your local rc file is actually being read and acted upon?


    🦛

      Thanks for getting back. Yeah, I just discovered the .perlcriticrc file is not working as I assumed it was. I'm about to go back to the documentation and fill my gap in knowledge of how .perlcriticrc files work. my .perlcriticrc file is in the directory above my test. I thought perlcritic searched up the directory tree for .perlcriticrc files. And it seemed to work. When I increased the severity setting in the rc file, I saw more warnings. So I figured it worked as I thought.

      But then I copied the .perlcriticrc file directly into my test directory and now the pesky warning is gone.

      So clearly I don't know how the perlcritic config files are found/used.

      $PM = "Perl Monk's";
      $MC = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar Parson";
      $nysus = $PM . ' ' . $MC;
      Click here if you love Perl Monks

      OK, so the ALE vim plugin I was using searches up the directory tree for the nearest perlcritic file. I have no idea why ALE was ignoring directives in the config but at any rate, that's not a perl problem.

      $PM = "Perl Monk's";
      $MC = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar Parson";
      $nysus = $PM . ' ' . $MC;
      Click here if you love Perl Monks

Re: Can't figure out how to quiet perlcritic and ignore RequireUseStrict perlcritic rule
by nysus (Parson) on Jan 15, 2024 at 18:06 UTC

    OK, problem solved by dropping .perlcritirc file in the same directory as my test. See comment above for gory details.

    Also, equivalent_modules=Test::Utils does in fact work and the error is suppressed with:

    [TestingAndDebugging::RequireUseStrict] equivalent_modules=Test::Utils

    $PM = "Perl Monk's";
    $MC = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar Parson";
    $nysus = $PM . ' ' . $MC;
    Click here if you love Perl Monks