Azure / Azure/bicep

Misleading Unused Variable Warnings if there's a syntax error in the file

Open
#4,557 1 comment 0 reactions 0 assignees View on GitHub
bug revisit
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

**Bicep version**
Bicep CLI version 0.4.613 (d826ce8411)

**Describe the bug**
If there is a syntax error in the file making it unparseable, the unused variable warning can fire even if the variable is actually used. In the below example, the `accountName` variable most certainly is used, but I presume the usage isn't detected as a knock on from the parser error (lack of closing brace on the resource).

**To Reproduce**
Build the following bicep snippet
```bicep
var accountName = 'SomeName'
resource x 'Microsoft.Storage/storageAccounts@2021-04-01' = {
name: accountName
```
![image](https://user-images.githubusercontent.com/289860/134492358-7d907bf8-fd8c-4ca1-8a97-49df391b43ed.png)

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the warning with the Bicep snippet in the issue and inspect the compiler diagnostics for the syntax error and unused-variable warning. Done means the incomplete resource still reports its syntax error without incorrectly warning that accountName is unused.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.