Wesley Dean
>

MegaLinter Plugins

3 min read

MegaLinter is an excellent piece of software that ships with support for more than 130 linters, scanners, formatters, style checkers, and policy enforcement tools. Even with all of this functionality, there can be times when you need something that's just not available out of the box. Fortunately, drafting a plugin often involves creating a single YAML file.

MegaLinter Plugins

A MegaLinter plugin -- actually, any tool included with MegaLinter -- is a single YAML file. The YAML file describes how to install and configure the required tooling, run the tool, and how to interpret the results.

Tooling Installation

Most tools included with MegaLinter run in a containerized context, so installation can be codified with a set of Dockerfile commands:

    install:
      dockerfile:
        - "RUN npm install -g dclint"

The RUN statement is just like someone would see in a Dockerfile like this:

FROM ubuntu:latest
RUN npm install -g dclint

Running Tools

Running a plugin is very similar in that you can specify a command to run in the container via a YAML line:

linters:
  - linter_name: dclint

Given this sample, dclint is specified as being the command to run when this plugin is invoked.

Additional arguments may be passed as a list via the cli_lint_extra_args directive.

Interpreting the Results

Telling MegaLinter how to interpret the results -- the output of the tool that was run -- is a little more involved as there's endless variety in how various tools return results.

Some tools include a count for the number of errors and warnings detected, some tools provide a line of text for each finding, some provide output that includes lines that, when they match a regular expression, indicate a finding.

Fortunately, MegaLinter supports all of these models and more.

  - cli_lint_errors_count: regex_number
    cli_lint_errors_regex: "(\\d+)\\s*errors?\\s*found"

The same applies to warnings:

- cli_lint_warnings_count: regex_number
  cli_lint_warnings_regex: "(\\d+)\\s*warnings?\\s*found"

Invoking Plugins

When you want to use a plugin, provide a link to the YAML file under a section of your .mega-linter.yml file named PLUGINS:

PLUGINS:
  - https://raw.githubusercontent.com/wesley-dean/mega-linter-plugin-dclint/refs/heads/main/mega-linter-plugin-dclint/dclint.megalinter-descriptor.yml

My MegaLinter Plugins

I have contributed several plugins that are available via GitHub:

Special Thanks

Thanks to Ryan Masters for recently contributing some updates to the dclint plugin.

More Information about MegaLinter Plugins

I have a book coming out shortly, Getting Started With MegaLinter that goes into depth about MegaLinter deployment, usage, customization, optimization, and extension through custom plugins and Large Language Models (LLMs).

Tags