Skip to content

perlcritic

GitHub stars GitHub release (latest SemVer) GitHub last commit GitHub commit activity GitHub contributors

perlcritic is a comprehensive static source code analysis engine for Perl that enforces coding standards and best practices. Based primarily on Damian Conway's "Perl Best Practices" book, it serves as an extensible framework for creating and applying consistent coding standards across Perl projects.

Key Features:

  • Extensive Policy Library: Over 100 built-in policies covering bugs, security, maintainability, complexity, and code style
  • Configurable Severity Levels: Five severity levels (1-5) allowing fine-tuned control over policy enforcement
  • Best Practices Foundation: Policies based on "Perl Best Practices" and community-established coding standards
  • Theme-Based Organization: Policies grouped by themes like bugs, security, performance, and maintainability
  • Inline Annotations: Selective policy disabling through source code comments and annotations
  • Extensible Framework: Support for custom policies and organizational coding standards
  • Detailed Reporting: Comprehensive violation reports with explanations and suggested fixes
  • Flexible Configuration: Project-specific configuration files for team-wide standards enforcement

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_COMMAND_REMOVE_ARGUMENTS User custom arguments to remove from command line before calling the linter
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
- project: Call the linter from the root of the project
file
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_UNSECURED_ENV_VARIABLES List of env variables explicitly not filtered before calling PERL_PERLCRITIC and its pre/post commands 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
PERL_PERLCRITIC_CLI_EXECUTABLE Override CLI executable ['perlcritic']

MegaLinter Flavors

This linter is available in the following flavors

Flavor Description Embedded linters Info
all Default MegaLinter Flavor 126 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 (file CLI lint mode)

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 :
# renovate: datasource=github-tags depName=skaji/cpm
ARG PERL_PERLCRITIC_VERSION=0.997024

RUN curl -fsSL https://raw.githubusercontent.com/skaji/cpm/refs/tags/${PERL_PERLCRITIC_VERSION}/cpm | perl - install -g --show-build-log-on-failure --without-build --without-test --without-runtime Perl::Critic \
    && rm -rf /root/.perl-cpm