Skip navigation

Tudor Constantin asked about extending Perl::Critic to calculate the total cost of violations. You can do this yourself without much work without any code changes to Perl::Critic. Perl::Critic has a --statistics-only option which doesn’t emit any individual violations, but just some figures about the code that it looked at. The output looks like this:

perl -Ilib bin/perlcritic --force -1 --statistics-only bin lib
   194 files.
 1,468 subroutines/methods.
15,194 statements.

45,950 lines, consisting of:
     6,342 blank lines.
     3,833 comment lines.
     2,275 data lines.
    16,388 lines of Perl code.
    17,112 lines of POD.

Average McCabe score of subroutines was 2.94.

2,951 violations.
Violations per file was 15.211.
Violations per statement was 0.194.
Violations per line of code was 0.064.

   13 severity 5 violations.
   31 severity 4 violations.
   32 severity 3 violations.
2,364 severity 2 violations.
  511 severity 1 violations.

    6 violations of BuiltinFunctions::ProhibitStringyEval.
    1 violations of ClassHierarchies::ProhibitAutoloading.
    2 violations of CodeLayout::ProhibitParensWithBuiltins.
  192 violations of CodeLayout::RequireTidyCode.
    4 violations of ControlStructures::ProhibitCStyleForLoops.
    1 violations of ControlStructures::ProhibitCascadingIfElse.
    6 violations of ControlStructures::ProhibitPostfixControls.
  165 violations of Documentation::PodSpelling.
1,736 violations of Documentation::RequirePodSections.
    2 violations of ErrorHandling::RequireCarping.
    2 violations of ErrorHandling::RequireCheckingReturnValueOfEval.
    1 violations of InputOutput::ProhibitBacktickOperators.
    2 violations of InputOutput::ProhibitInteractiveTest.
    7 violations of InputOutput::RequireBriefOpen.
    1 violations of InputOutput::RequireCheckedSyscalls.
  579 violations of Miscellanea::RequireRcsKeywords.
    1 violations of NamingConventions::Capitalization.
    1 violations of RegularExpressions::ProhibitComplexRegexes.
   86 violations of RegularExpressions::ProhibitUnusualDelimiters.
   14 violations of RegularExpressions::RequireBracesForMultiline.
    4 violations of Subroutines::ProhibitExplicitReturnUndef.
    6 violations of Subroutines::ProhibitUnusedPrivateSubroutines.
   20 violations of Subroutines::RequireArgUnpacking.
    3 violations of Subroutines::RequireFinalReturn.
    1 violations of TestingAndDebugging::ProhibitNoStrict.
    1 violations of TestingAndDebugging::ProhibitNoWarnings.
    2 violations of ValuesAndExpressions::ProhibitMagicNumbers.
   37 violations of ValuesAndExpressions::ProhibitNoisyQuotes.
   50 violations of ValuesAndExpressions::RequireInterpolationOfMetachars.
   11 violations of Variables::ProhibitPackageVars.
    6 violations of Variables::ProhibitReusedNames.
    1 violations of Variables::ProtectPrivateVars.

Munging this output to fit Mr. Constantin’s desired output is left as an exercise for the reader.

%d bloggers like this: