Skip to content

perlcritic

perlcritic documentation

Perl-Critic - GitHub

Configuration in MegaLinter

Variable Description Default value
PERL_PERLCRITIC_ARGUMENTS User custom arguments to add in linter CLI call
Ex: -s --foo "bar"
PERL_PERLCRITIC_FILTER_REGEX_INCLUDE Custom regex including filter
Ex: (src\|lib)
Include every file
PERL_PERLCRITIC_FILTER_REGEX_EXCLUDE Custom regex excluding filter
Ex: (test\|examples)
Exclude no file
PERL_PERLCRITIC_CLI_LINT_MODE Override default CLI lint mode
- file: Calls the linter for each file
- list_of_files: Call the linter with the list of files as argument
- project: Call the linter from the root of the project
{linter.cli_lint_mode}
PERL_PERLCRITIC_FILE_EXTENSIONS Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all files
Ex: [".py", ""]
[".pl", ".pm", ".t", ""]
PERL_PERLCRITIC_FILE_NAMES_REGEX File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files
Ex: ["Dockerfile(-.+)?", "Jenkinsfile"]
Include every file
PERL_PERLCRITIC_PRE_COMMANDS List of bash commands to run before the linter None
PERL_PERLCRITIC_POST_COMMANDS List of bash commands to run after the linter None
PERL_PERLCRITIC_DISABLE_ERRORS Run linter but consider errors as warnings false
PERL_PERLCRITIC_DISABLE_ERRORS_IF_LESS_THAN Maximum number of errors allowed 0

MegaLinter Flavours

This linter is available in the following flavours

Flavor Description Embedded linters Info
all Default MegaLinter Flavor 95 Docker Image Size (tag) Docker Pulls

Behind the scenes

How are identified applicable files

  • File extensions: .pl, .pm, .t, ``
  • Detected file content (regex): #!/usr/bin/env perl, #!/usr/bin/perl

How the linting is performed

  • perlcritic is called one time by identified file

Example calls

perlcritic myfile.pl

Help content

Usage:
      perlcritic [-12345 | --brutal | --cruel | --harsh | --stern | --gentle]
                 [--severity number | name] [{-p | --profile} file | --noprofile]
                 [--top [ number ]] [--theme expression] [--include pattern]
                 [--exclude pattern] [{-s | --single-policy} pattern]
                 [--only | --noonly] [--profile-strictness {warn|fatal|quiet}]
                 [--force | --noforce] [--statistics] [--statistics-only]
                 [--count | -C] [--verbose {number | format}] [--allow-unsafe]
                 [--color | --nocolor] [--pager pager] [--quiet]
                 [--color-severity-highest color_specification]
                 [--color-severity-high color_specification]
                 [--color-severity-medium color_specification]
                 [--color-severity-low color_specification]
                 [--color-severity-lowest color_specification]
                 [--files-with-violations | -l]
                 [--files-without-violations | -L]
                 [--program-extensions file_name_extension]
                 {FILE | DIRECTORY | STDIN}

      perlcritic --profile-proto

      perlcritic { --list | --list-enabled | --list-themes | --doc pattern [...] }

      perlcritic { --help | --options | --man | --version }

Installation on mega-linter Docker image

  • Dockerfile commands :
RUN curl --retry 5 --retry-delay 5 -sL https://cpanmin.us/ | perl - -nq --no-wget Perl::Critic

Example success log

Results of perlcritic linter (version 1.138)
See documentation on https://megalinter.github.io/descriptors/perl_perlcritic/
-----------------------------------------------

[SUCCESS] .automation/test/perl/perl_good_1.pl
    .automation/test/perl/perl_good_1.pl source OK

[SUCCESS] .automation/test/perl/perl_good_2
    .automation/test/perl/perl_good_2 source OK

Example error log

Results of perlcritic linter (version 1.138)
See documentation on https://megalinter.github.io/descriptors/perl_perlcritic/
-----------------------------------------------

[ERROR] .automation/test/perl/perl_bad_1.pl
    Code before strictures are enabled at line 14, column 1.  See page 429 of PBP.  (Severity: 5)