Bicep Linter Basics
Bicep Linter Basics

Azure Bicep – Getting started with Linter

In this article, we are going to discuss about how to Setup Linter for bicep. It will also show how to enable / disable specific rules.

What is Linter ?

Linting is a process to ensure consistency / readability / maintainability in the source code. We may already have used similar tools for other languages like Angular Linter, TypeScript Linter, etc. Similarly, for bicep as well, there is a linter available. The bicep linter will check for any best practices violations and also for syntax errors.

The linter is integrated into the Bicep CLI and the Bicep extension for Visual Studio Code. To use it, you must have version 0.4 or later.

How to setup Bicep Linter ?

There are no special instructions for configuring Linter for bicep. It by default comes with Bicep CLI and Bicep Extension for Visual Studio Code. The snapshot given below shows how the warning is shown in the VS Code.

VS Code – Bicep Linter shows a warning for unused variable

The PROBLEMS pane shows all the errors and warning would be shown in the VS Code. OR when you hover over the line with problem, you will be able to view the details.

When you click on the problematic area, you will be able to view a light bulb icon. You can click on that icon to view the steps in order to fix the problem. Or else, on the hover tooltip, you can click on Quick Fix link from the popup.

Use in CLI

We can use the Bicep CLI to view the liter warnings and errors. We can use bicep build <file-name> command to build the template. We can use this command in the CI / CD pipeline to ensure the consistency / quality of the bicep files which are getting committed to the repository.

Handling False Positives

Sometimes, it may happen that some issues reported by linter may not be accurate and may be false positive. In such cases, we may want to linter warning for particular section of code. We can use #disable-next-line <rule-name>, just above the line which has the issue.

Custom RuleSet for the Solution

The default set of linter rules is minimal and taken from arm-ttk test cases. We can also customize the rule set based on our needs. We need to create a bicepconfig.json file. In that file, we can define the rules to be applied. We will talk about this file in the coming article.

I hope you find this information helpful. Let me know your thoughts.

Leave a Reply Cancel reply