### Run MegaLinter Assisted Installation Source: https://megalinter.io/latest/install-assisted Execute this command in your repository's root directory to start the interactive setup. It will guide you through generating necessary configuration files. ```bash npx mega-linter-runner --install ``` -------------------------------- ### Example NPM Package Installation Source: https://megalinter.io/latest/json-schemas/descriptor.html Shows an example of an NPM package identifier that can be used for installation. ```npm [ "sfdx-cli" ] ``` -------------------------------- ### Setup Custom MegaLinter Flavor Source: https://megalinter.io/latest/custom-flavors Run this command in your repository folder to initiate the custom flavor setup. It guides you through selecting a label and linters. ```bash npx mega-linter-runner@beta --custom-flavor-setup ``` -------------------------------- ### Linter CLI Commands Examples (golangci-lint) Source: https://megalinter.io/latest/json-schemas/descriptor.html Provides examples of how to run golangci-lint with and without a configuration file. Use these examples to document CLI usage. ```bash [ "golangci-lint run myfile.go", "golangci-lint run -c .golangci.yml myfile.go" ] ``` -------------------------------- ### Linter CLI Commands Examples (eslint) Source: https://megalinter.io/latest/json-schemas/descriptor.html Provides examples of how to run eslint with and without a configuration file. Use these examples to document CLI usage. ```bash [ "eslint myfile.js", "eslint -c .eslintrc.yml --no-eslintrc --no-ignore myfile.js" ] ``` -------------------------------- ### Configure Pre-commands for pnpm Installation Source: https://megalinter.io/latest/descriptors/json_eslint_plugin_jsonc Use pre-commands to install project dependencies with pnpm before linting. This example enables pnpm and installs dependencies within the `workspace` directory. ```yaml JSON_ESLINT_PLUGIN_JSONC_PRE_COMMANDS: - command: corepack enable pnpm cwd: workspace continue_if_failed: false - command: pnpm install --frozen-lockfile --ignore-scripts cwd: workspace continue_if_failed: false JSON_ESLINT_PLUGIN_JSONC_CLI_EXECUTABLE: node_modules/.bin/eslint ``` -------------------------------- ### Local Development Environment Setup Source: https://megalinter.io/latest/contributing Commands to set up the Python virtual environment and install dependencies for local development. This is necessary for testing changes on your desktop. ```bash make reinitialization ``` ```bash make bootstrap ``` -------------------------------- ### Install Dockerfile Requirements Source: https://megalinter.io/latest/json-schemas/descriptor.html List Dockerfile instructions required to install the linter. ```json { "dockerfile": [ "FROM accurics/terrascan:latest AS terrascan", "COPY --from=terrascan /go/bin/terrascan /usr/bin/", "RUN terrascan init" ] } ``` -------------------------------- ### Custom Bash Command Example Source: https://megalinter.io/latest/json-schemas/descriptor.html Example of a simple bash command to be executed. ```bash "npm run test" ``` ```bash "echo \"This is a custom command\"" ``` -------------------------------- ### Build and Serve Documentation Source: https://megalinter.io/latest/contributing Build the documentation and start a local server to preview changes. Automatically updates on file changes. ```bash hatch run build:serve ``` -------------------------------- ### Example Dockerfile Instructions List Source: https://megalinter.io/latest/json-schemas/descriptor.html A list of Dockerfile instructions to configure the Java environment. ```json [ "ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk", "ENV PATH=\"$$JAVA_HOME/bin:$PATH\"" ] ``` -------------------------------- ### Linter Definition Example Source: https://megalinter.io/latest/json-schemas/descriptor.html Defines the configuration for the ESLint linter, including installation commands, configuration file names, and example usage. ```json { "cli_config_extra_args": [ "--no-eslintrc", "--no-ignore" ], "config_file_name": ".eslintrc.yml", "examples": [ "eslint myfile.js", "eslint -c .eslintrc.yml --no-eslintrc --no-ignore myfile.js" ], "install": { "npm": [ "eslint", "eslint-config-airbnb", "eslint-config-prettier", "eslint-plugin-jest", "eslint-plugin-prettier", "babel-eslint" ] }, "linter_banner_image_url": "https://d33wubrfki0l68.cloudfront.net/3b5ac7586466159bb6f237b633bfc4f5a8d5acf8/ee0a1/assets/img/posts/eslint-collective.png", "linter_name": "eslint", "linter_url": "https://eslint.org", "name": "JAVASCRIPT_ES" } ``` -------------------------------- ### PHP Installation Commands Source: https://megalinter.io/latest/descriptors/php Dockerfile commands for setting up the PHP environment, including alternative PHP version installation and Composer setup. ```dockerfile RUN update-alternatives --install /usr/bin/php php /usr/bin/php84 110 COPY --link --from=composer/composer:2-bin /composer /usr/bin/composer ENV COMPOSER_HOME=/usr/local/composer ENV PATH="/usr/local/composer/vendor/bin:${PATH}" ``` -------------------------------- ### Bicep CLI Build Example Source: https://megalinter.io/latest/descriptors/bicep_bicep_linter Example of building a Bicep file using the Bicep CLI. ```bash bicep build infra.bicep; ``` -------------------------------- ### Install Revive in Dockerfile Source: https://megalinter.io/latest/descriptors/go_revive Commands to install the Go Revive linter within a Dockerfile, including setting up the Go environment and installing the linter binary. This is part of the MegaLinter Docker image setup. ```dockerfile # Parent descriptor install # renovate: datasource=repology depName=alpine_3_24/go versioning=loose ARG GO_ALPINE_VERSION=1.26.3-r0 RUN apk add --no-cache \ go=${GO_ALPINE_VERSION} # Linter install # renovate: datasource=github-tags depName=mgechev/revive ARG GO_REVIVE_VERSION=v1.15.0 # renovate: datasource=docker depName=golang versioning=semver ARG GO_IMAGE_VERSION=1.26.4 FROM golang:${GO_IMAGE_VERSION}-alpine AS revive ## The golang image used as a builder is a temporary workaround (https://github.com/mgechev/revive/issues/787) ## for the released revive binaries not returning version numbers (devel). ## The install command should then be what is commented in the go.megalinter-descriptor.yml ARG GO_REVIVE_VERSION RUN GOBIN=/usr/bin go install github.com/mgechev/revive@$GO_REVIVE_VERSION COPY --link --from=revive /usr/bin/revive /usr/bin/revive ``` -------------------------------- ### Luacheck with Configuration File Source: https://megalinter.io/latest/descriptors/lua_luacheck This example demonstrates how to specify a custom configuration file for luacheck. ```bash luacheck --config .chktexrc myfile.lua ``` -------------------------------- ### Linter Definitions Example Source: https://megalinter.io/latest/json-schemas/descriptor.html An array of linter definitions, including installation instructions, configuration examples, and URLs for JavaScript linters like ESLint and Standard. ```json [ { "cli_config_extra_args": [ "--no-eslintrc", "--no-ignore" ], "config_file_name": ".eslintrc.yml", "examples": [ "eslint myfile.js", "eslint -c .eslintrc.yml --no-eslintrc --no-ignore myfile.js" ], "install": { "npm": [ "eslint", "eslint-config-airbnb", "eslint-config-prettier", "eslint-plugin-jest", "eslint-plugin-prettier", "@babel/eslint-parser" ] }, "linter_banner_image_url": "https://d33wubrfki0l68.cloudfront.net/3b5ac7586466159bb6f237b633bfc4f5a8d5acf8/ee0a1/assets/img/posts/eslint-collective.png", "linter_name": "eslint", "linter_url": "https://eslint.org", "name": "JAVASCRIPT_ES" }, { "examples": [ "standard myfile.js" ], "install": { "npm": [ "standard" ] }, "linter_banner_image_url": "https://github.com/standard/standard/raw/master/sticker.png", "linter_name": "standard", "linter_url": "https://github.com/standard/standard", "name": "JAVASCRIPT_STANDARD" } ] ``` -------------------------------- ### Example Dockerfile Instructions for Java Environment Source: https://megalinter.io/latest/json-schemas/descriptor.html Provides Dockerfile instructions to set JAVA_HOME and update the PATH for Java 11. ```json { "dockerfile": [ "ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk", "ENV PATH=\"$$JAVA_HOME/bin:$PATH\"" ] } ``` -------------------------------- ### Specify Pylint and typing-extensions versions for PIP Source: https://megalinter.io/latest/descriptors/python_pylint Example of how to specify exact versions for Pylint and typing-extensions when installing via PIP. ```bash pylint==4.0.6 typing-extensions==4.15.0 ``` -------------------------------- ### Basic Cppcheck File Analysis Source: https://megalinter.io/latest/descriptors/cpp_cppcheck This is a basic example of how to call cppcheck on a single file. Ensure cppcheck is installed and in your PATH. ```bash cppcheck myfile.cpp ``` -------------------------------- ### File Activation Example Source: https://megalinter.io/latest/json-schemas/descriptor.html Specifies configuration file names that, if found, will activate the descriptor. ```json [ ".editorconfig", ".eslintrc.json" ] ``` -------------------------------- ### Basic Ollama Configuration Source: https://megalinter.io/latest/llm-provider/llm_provider_ollama Specifies the LLM provider and model name for MegaLinter. 'codellama:7b' is an example; any installed Ollama model can be used. ```yaml LLM_PROVIDER: ollama LLM_MODEL_NAME: codellama:7b # Any installed Ollama model ``` -------------------------------- ### Azure CLI Bicep Build Example Source: https://megalinter.io/latest/descriptors/bicep_bicep_linter Example of building a Bicep file using the Azure CLI. ```bash az bicep build -f infra.bicep ``` -------------------------------- ### Basic Cppcheck File Call Source: https://megalinter.io/latest/descriptors/c_cppcheck This is a basic example of how to call cppcheck on a single C++ file. Ensure cppcheck is installed and in your PATH. ```bash cppcheck myfile.cpp ``` -------------------------------- ### Troubleshooting: Ensure Ollama is Running Source: https://megalinter.io/latest/llm-provider/llm_provider_ollama Command to start the Ollama server. Use this if you encounter 'Connection refused' errors. ```bash ollama serve ``` -------------------------------- ### Install Pylint Plugin via Pre-command Source: https://megalinter.io/latest/descriptors/python_pylint Example of how to pre-install a Pylint plugin using pip within a MegaLinter pre-command. This is useful when Pylint fails to load a plugin. ```yaml PYTHON_PYLINT_PRE_COMMANDS: - command: "pip install pylint-django" venv: pylint continue_if_failed: false ``` -------------------------------- ### Proselint CLI Example Call Source: https://megalinter.io/latest/descriptors/spell_proselint Example of how to invoke the proselint command-line tool with a configuration file and multiple markdown and text files. ```bash proselint --config .proselintrc myfile.md myfile2.txt myfile3.rst ``` -------------------------------- ### Scan Source Directory Recursively (Help Example) Source: https://megalinter.io/latest/descriptors/repository_osv_scanner Example from help documentation for scanning a source directory recursively. Replace with the actual path. ```bash osv-scanner scan source -r ``` -------------------------------- ### Install PSScriptAnalyzer in Dockerfile Source: https://megalinter.io/latest/descriptors/powershell_powershell Installs the PSScriptAnalyzer module for PowerShell within the Docker image. It uses the pwsh command to execute the installation script. ```Dockerfile # Linter install # renovate: datasource=nuget depName=PSScriptAnalyzer registryUrl=https://www.powershellgallery.com/api/v2/ ARG PSSA_VERSION='1.25.0' RUN pwsh -c 'Install-Module -Name PSScriptAnalyzer -RequiredVersion ${PSSA_VERSION} -Scope AllUsers -Force' ``` -------------------------------- ### Install DevSkim CLI on Docker Image Source: https://megalinter.io/latest/descriptors/repository_devskim Dockerfile commands to install the DevSkim CLI using the dotnet tool installer. Ensure the dotnet10-sdk is available. ```dockerfile # renovate: datasource=nuget depName=Microsoft.CST.DevSkim.CLI ARG REPOSITORY_DEVSKIM_VERSION=1.0.70 RUN apk add --no-cache dotnet10-sdk && install -d /usr/local/dotnet-tools ENV PATH="${PATH}:/usr/local/dotnet-tools" RUN dotnet tool install --allow-roll-forward --tool-path /usr/local/dotnet-tools Microsoft.CST.DevSkim.CLI --version ${REPOSITORY_DEVSKIM_VERSION} ``` -------------------------------- ### Example Custom Command Configuration Source: https://megalinter.io/latest/json-schemas/configuration.html An example of a custom command configuration, including the command to execute, whether to continue if it fails, and the working directory. ```json [ { "command": "composer install", "continue_if_failed": false, "cwd": "workspace" } ] ``` -------------------------------- ### Mypy Pre-install Type Stubs Example Source: https://megalinter.io/latest/descriptors/python_mypy Example of how to pre-install required type stub packages for mypy using a pre-command in your .mega-linter.yml. This is useful when mypy's auto-installation fails. ```yaml PYTHON_MYPY_PRE_COMMANDS: - command: "pip install types-requests types-PyYAML" venv: mypy continue_if_failed: false ``` -------------------------------- ### Install Ktlint on MegaLinter Docker Image Source: https://megalinter.io/latest/descriptors/kotlin_ktlint Add these Dockerfile commands to install Ktlint. Ensure Java environment variables are set before installing the linter. ```dockerfile # Parent descriptor install ENV JAVA_HOME=/usr/lib/jvm/java-21-openjdk ENV PATH="$JAVA_HOME/bin:${PATH}" # Linter install # renovate: datasource=github-tags depName=pinterest/ktlint ARG KTLINT_VERSION=1.8.0 RUN curl --retry 5 --retry-delay 5 -sSLO https://github.com/pinterest/ktlint/releases/download/${KTLINT_VERSION}/ktlint && \ chmod a+x ktlint && \ mv "ktlint" /usr/bin/ ``` -------------------------------- ### Bootstrap Development Environment Source: https://megalinter.io/latest/contributing Initialize the Python virtual environment and install all necessary development dependencies. ```bash make bootstrap ``` ```bash uv pip install -e . ``` -------------------------------- ### Install clj-kondo in Docker Image Source: https://megalinter.io/latest/descriptors/clojure_clj_kondo These Dockerfile commands download and install a specific version of clj-kondo. It uses a curl command to fetch the installation script and then executes it. ```dockerfile # renovate: datasource=github-tags depName=clj-kondo/clj-kondo ARG CLJ_KONDO_VERSION=2025.01.16 RUN curl --retry 5 --retry-delay 5 -sLO https://raw.githubusercontent.com/clj-kondo/clj-kondo/refs/tags/v${CLJ_KONDO_VERSION}/script/install-clj-kondo && chmod +x install-clj-kondo && ./install-clj-kondo --version "$CLJ_KONDO_VERSION" ``` -------------------------------- ### Scan Local Image Archive and Serve HTML (Help Example) Source: https://megalinter.io/latest/descriptors/repository_osv_scanner Example for scanning a local container image archive (e.g., a tar file) and generating an HTML report. Replace with the archive file name. ```bash osv-scanner scan image --serve --archive ``` -------------------------------- ### Protolint Usage Help Source: https://megalinter.io/latest/descriptors/protobuf_protolint Displays the available options and usage for the protolint lint command. ```bash Usage of lint: -add-reporter value Adds a reporter to the list of reporters to use. The format should be 'name of reporter':'Path-To_output_file' -auto_disable value mode that the command line automatically disable some of the problems. Available auto_disable are "next" and "this". -config_dir_path string path/to/the_directory_including_protolint.yaml -config_path string path/to/protolint.yaml. Note that if both are set, config_dir_path is ignored. -fix mode that the command line automatically fix some of the problems -no-error-on-unmatched-pattern exits with 0 when no file is matched -output_file string path/to/output.txt -plugin value plugins to provide custom lint rule set. Note that it's necessary to specify it as path format' -reporter value formatter to output results in the specific format. Available reporters are "plain"(default), "junit", "json", "sarif", and "unix". -v verbose output that includes parsing process details ``` -------------------------------- ### Install CSharpier in Docker Image Source: https://megalinter.io/latest/descriptors/csharp_csharpier Commands to install the CSharpier .NET tool within a Docker image. Ensure the dotnet SDK is installed first and the PATH is updated. ```dockerfile # Parent descriptor install RUN apk add --no-cache dotnet10-sdk && install -d /usr/local/dotnet-tools ENV PATH="${PATH}:/usr/local/dotnet-tools" # Linter install # renovate: datasource=nuget depName=csharpier ARG CSHARP_CSHARPIER_VERSION=1.2.6 RUN dotnet tool install --allow-roll-forward --tool-path /usr/local/dotnet-tools csharpier --version "${CSHARP_CSHARPIER_VERSION}" ``` -------------------------------- ### Install Syft using a Dockerfile Source: https://megalinter.io/latest/descriptors/repository_syft This snippet shows how to install a specific version of Syft within a Dockerfile using a curl command to download and execute the official installation script. ```Dockerfile # renovate: datasource=github-tags depName=anchore/syft ARG REPOSITORY_SYFT_VERSION=1.46.0 RUN curl -sSfL https://raw.githubusercontent.com/anchore/syft/refs/tags/v${REPOSITORY_SYFT_VERSION}/install.sh | sh -s -- -b /usr/local/bin ``` -------------------------------- ### List Dockerfile Instructions Source: https://megalinter.io/latest/json-schemas/descriptor.html Provide a list of Dockerfile instructions to be integrated into generated Dockerfiles. This can include FROM, COPY, and RUN commands. ```json [ "FROM accurics/terrascan:latest AS terrascan", "COPY --from=terrascan /go/bin/terrascan /usr/bin/", "RUN terrascan init" ] ```