4

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?)

toolic
  • 57,801
  • 17
  • 75
  • 117
CodeGorilla
  • 811
  • 1
  • 6
  • 21
  • Can you turn `## critic` back on at the end of the file? Also, is this pre-compile thing code you're using inside one of your code files, or is it something you've written in its own file? Or maybe a third-party dependency that just happens to live in your repository to make deployment easier? – simbabque Jan 10 '19 at 16:09
  • @simbabque - this is a distinct & separate package, as created using `Parse::RecDescent->Precompile( { -standalone => 1, }, $grammar, 'My::Specific::Class' )` – CodeGorilla Jan 11 '19 at 07:33

1 Answers1

3

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.

haukex
  • 2,973
  • 9
  • 21
  • I'm actually running a `brutal` level, which makes the whole Package un-checkable... however you have answered one of the questions asked – CodeGorilla Jan 11 '19 at 08:36
  • yes I did.... I've been distracted by a broken service - however I'll also try that. This would give two options: (a) exclude the whole file, or (b) allow the 'no critic' options - which is nice – CodeGorilla Jan 15 '19 at 15:56