Search code examples
perlperl-criticparse-recdescent

Disable critic for an entire file - Parse::RecDescent precompiled parser & PerlCritic/Tidyall


I'm trying to remove an error from my sanity-checking [when I push code to my git repo, there's a hook that checks the code with perltidy & critic... using tidyall as the handler.]

The specific issue I have is with a pre-compiled Grammar Parser.... and this is not something I want to dive in & fix (sorry - that's outside my comfort zone)

If I add a simple ## no critic to the start of the file, then

perlcritic path/to/class/file.pm

comes back

path/to/class/file.pm source OK

however

tidyall --check-only -r .

comes back with

perlcritic /tmp/Code-TidyAll-Frb0/path/to/class/file.pm failed
    exited with 2 - output was:
Unrestricted '## no critic' annotation at line 6, column 1. (Miscellanea::ProhibitUnrestrictedNoCritic, severity 3)

I know I can fix this in the tidyall.ini file:

[PerlCritic lib]
select = **/*.{pm}
ignore = **/class/file.pm

.... however I feel there should be a cleaner solution.

(or, why doesn't tidyall critique the same as critic?)


Solution

  • why doesn't tidyall critique the same as critic?

    A simple perlcritic on the command line defaults to severity 5, unless you've configured something different in your ~/.perlcriticrc. The rule ProhibitUnrestrictedNoCritic defaults to severity 3, so your tidyall is running Perl::Critic with at least severity 3. As per its documentation, you can change that via something like this in the tidyall.ini:

    [PerlCritic]
    argv = -severity 4
    

    And then tidyall's checks should be the same as a perlcritic -4 from the command line. (Unless you've configured custom severity levels in your .perlcriticrc.)


    Update: As per your comment, you want to check everything at the "brutal" level. In that case, you can create a perlcriticrc file containing the line [-Miscellanea::ProhibitUnrestrictedNoCritic] which will disable that policy, and then point perlcritic at that file by adding the command-line argument --profile /path/to/custom/perlcriticrc.