Skip to content

bicep_linter

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

By default, Bicep linter errors are set as warnings. To customize linter settings, use a bicepconfig.json file. For more information, see the documentation for the Bicep Linter

bicep_linter documentation

bicep - GitHub

Configuration in MegaLinter

Variable Description Default value
BICEP_BICEP_LINTER_ARGUMENTS User custom arguments to add in linter CLI call
Ex: -s --foo "bar"
BICEP_BICEP_LINTER_FILTER_REGEX_INCLUDE Custom regex including filter
Ex: (src\|lib)
Include every file
BICEP_BICEP_LINTER_FILTER_REGEX_EXCLUDE Custom regex excluding filter
Ex: (test\|examples)
Exclude no file
BICEP_BICEP_LINTER_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
BICEP_BICEP_LINTER_FILE_EXTENSIONS Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all files
Ex: [".py", ""]
[".bicep"]
BICEP_BICEP_LINTER_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
BICEP_BICEP_LINTER_PRE_COMMANDS List of bash commands to run before the linter None
BICEP_BICEP_LINTER_POST_COMMANDS List of bash commands to run after the linter None
BICEP_BICEP_LINTER_UNSECURED_ENV_VARIABLES List of env variables explicitly not filtered before calling BICEP_BICEP_LINTER and its pre/post commands None
BICEP_BICEP_LINTER_DISABLE_ERRORS Run linter but consider errors as warnings false
BICEP_BICEP_LINTER_DISABLE_ERRORS_IF_LESS_THAN Maximum number of errors allowed 0
BICEP_BICEP_LINTER_CLI_EXECUTABLE Override CLI executable ['bicep']

IDE Integration

Use bicep_linter in your favorite IDE to catch errors before MegaLinter !

IDE Extension Name Install
Visual Studio Code VSCode Bicep Install in VSCode

MegaLinter Flavours

This linter is available in the following flavours

Flavor Description Embedded linters Info
all Default MegaLinter Flavor 113 Docker Image Size (tag) Docker Pulls
dotnet Optimized for C, C++, C# or VB based projects 59 Docker Image Size (tag) Docker Pulls

Behind the scenes

How are identified applicable files

  • File extensions: .bicep

How the linting is performed

  • bicep_linter is called one time by identified file (file CLI lint mode)

Example calls

# Bicep CLI 
bicep build infra.bicep;

# Azure CLI 
az bicep build -f infra.bicep

Help content

Bicep CLI version 0.17.1 (d423d61882)

Usage:
  bicep build [options] <file>
    Builds a .bicep file.

    Arguments:
      <file>        The input file

    Options:
      --outdir <dir>    Saves the output at the specified directory.
      --outfile <file>  Saves the output as the specified file path.
      --stdout          Prints the output to stdout.
      --no-restore      Builds the bicep file without restoring external modules.

    Examples:
      bicep build file.bicep
      bicep build file.bicep --stdout
      bicep build file.bicep --outdir dir1
      bicep build file.bicep --outfile file.json
      bicep build file.bicep --no-restore

    bicep format [options] <file>
    Formats a .bicep file.

    Arguments:
      <file>        The input file

    Options:
      --outdir <dir>        Saves the output at the specified directory.
      --outfile <file>      Saves the output as the specified file path.
      --stdout              Prints the output to stdout.
      --newline             Set newline char. Valid values are ( Auto | LF | CRLF | CR ).
      --indentKind          Set indentation kind. Valid values are ( Space | Tab ).
      --indentSize          Number of spaces to indent with (Only valid with --indentKind set to Space).
      --insertFinalNewline  Insert a final newline.

    Examples:
      bicep format file.bicep
      bicep format file.bicep --stdout
      bicep format file.bicep --outdir dir1
      bicep format file.bicep --outfile file.json
      bicep format file.bicep --indentKind Tab

  bicep decompile [options] <file>
    Attempts to decompile a template .json file to .bicep.

    Arguments:
      <file>        The input file

    Options:
      --outdir <dir>    Saves the output at the specified directory.
      --outfile <file>  Saves the output as the specified file path.
      --stdout          Prints the output to stdout.
      --force           Allows overwriting the output file if it exists (applies only to 'bicep decompile').

    Examples:
      bicep decompile file.json
      bicep decompile file.json --stdout
      bicep decompile file.json --outdir dir1
      bicep decompile file.json --force
      bicep decompile file.json --outfile file.bicep

  bicep generate-params [options] <file>
    Builds .parameters.json file from the given bicep file, updates if there is an existing parameters.json file.

    Arguments:
      <file>        The input file

    Options:
      --no-restore      Generates the parameters file without restoring external modules.
      --outdir <dir>    Saves the output at the specified directory.
      --outfile <file>  Saves the output as the specified file path.
      --stdout          Prints the output to stdout.

    Examples:
      bicep generate-params file.bicep
      bicep generate-params file.bicep --no-restore
      bicep generate-params file.bicep --stdout
      bicep generate-params file.bicep --outdir dir1
      bicep generate-params file.bicep --outfile file.parameters.json


  bicep publish <file> --target <ref>
    Publishes the .bicep file to the module registry.

    Arguments:
      <file>        The input file (can be a Bicep file or an ARM template file)
      <ref>         The module reference

    Options:
      --documentationUri  Module documentation uri
      --force             Overwrite existing published module or file

    Examples:
      bicep publish file.bicep --target br:example.azurecr.io/hello/world:v1
      bicep publish file.bicep --target br:example.azurecr.io/hello/world:v1 --force
      bicep publish file.json --target br:example.azurecr.io/hello/world:v1
      bicep publish file.json --target br:example.azurecr.io/hello/world:v1 --documentationUri https://github.com/hello-world/README.md

  bicep restore <file>
    Restores external modules from the specified Bicep file to the local module cache.

    Arguments:
      <file>        The input file

 bicep [options]
    Options:
      --version              -v   Shows bicep version information
      --help                 -h   Shows this usage information
      --license                   Prints license information
      --third-party-notices       Prints third-party notices


  bicep build-params <file>
    Builds .bicepparam file.

    Arguments:
      <file>        The input Bicepparam file

    Options:
      --bicep-file <file> Verifies if the specified bicep file path matches the one provided in the params file using declaration
      --outfile <file>  Saves the param output json as the specified file path.
      --stdout          Prints the param and bicep json output to stdout.
      --no-restore      Builds the bicep file (referenced in using declaration) without restoring external modules.

    Examples:
      bicep build-params params.bicepparam
      bicep build-params params.bicepparam --stdout
      bicep build-params params.bicepparam --outfile otherParams.json
      bicep build-params params.bicepparam --no-restore


Installation on mega-linter Docker image

  • Dockerfile commands :
ARG BICEP_EXE='bicep'
ARG BICEP_URI='https://github.com/Azure/bicep/releases/latest/download/bicep-linux-musl-x64'
ARG BICEP_DIR='/usr/local/bin'
RUN curl --retry 5 --retry-delay 5 -sLo ${BICEP_EXE} "${BICEP_URI}" \
    && chmod +x "${BICEP_EXE}" \
    && mv "${BICEP_EXE}" "${BICEP_DIR}"