Add linter rule to warn for unrecognized resource types in reference/list* functions#19303
Merged
majastrz merged 2 commits intoAzure:mainfrom Mar 31, 2026
Merged
Add linter rule to warn for unrecognized resource types in reference/list* functions#19303majastrz merged 2 commits intoAzure:mainfrom
majastrz merged 2 commits intoAzure:mainfrom
Conversation
Member
Author
|
@copilot please fix CI/CD errors. |
majastrz
reviewed
Mar 31, 2026
| public new const string Code = "use-recognized-resource-type"; | ||
|
|
||
| private static readonly Regex ResourceTypeRegex = new( | ||
| "^ [a-z]+\\.[a-z]+ (\\/ [a-z]+)+ $", |
Member
There was a problem hiding this comment.
There is a copy of this regex in UseRecentApiVersionRule. Could we move this into some sort of "constants" or "shared" class in the same directory?
majastrz
approved these changes
Mar 31, 2026
…list* functions Fixes Azure#19172 Adds a new linter rule 'use-recognized-resource-type' that emits a warning when a 'reference' or 'list*' function call uses a resource type that is not recognized by Bicep's type system. The rule: - Inspects the first argument of reference() and list*() calls - Extracts resource types from string literals, variable references, and resourceId() wrapper calls - Checks the type against known Azure resource types - Suggests similar type names via spell-checking when available - Defaults to Warning level (PotentialCodeIssues category)
- Extract ResourceTypeRegex into LinterResourceTypePatterns shared class - Update UseRecognizedResourceTypeRule and UseRecentApiVersionRule to use shared regex - Update Outputs_CRLF and Variables_LF baseline diagnostics for new rule
8552e9f to
6cdd9cb
Compare
majastrz
approved these changes
Mar 31, 2026
Contributor
|
Test this change out locally with the following install scripts (Action run 23817454767) VSCode
Azure CLI
|
Copilot AI
pushed a commit
that referenced
this pull request
Apr 1, 2026
…list* functions (#19303) ## Description Fixes #19172 Adds a new linter rule `use-recognized-resource-type` that emits a warning when a `reference` or `list*` function call uses a resource type that is not recognized by Bicep's type system. ### What the rule does - Inspects the first argument of `reference()` and `list*()` function calls - Extracts resource types from string literals, variable references, and `resourceId()` wrapper calls - Checks the extracted type against known Azure resource types via `ApiVersionProvider` - Suggests similar type names via spell-checking when the type is unrecognized - Defaults to **Warning** level (`PotentialCodeIssues` category) ### Example ```bicep // This will emit a warning because 'Microsoft.Foo/bar' is not a recognized resource type output foo object = reference('Microsoft.Foo/bar', '2020-01-01') ``` ### Files changed | File | Purpose | |------|---------| | `src/Bicep.Core/Analyzers/Linter/Rules/UseRecognizedResourceTypeRule.cs` | New linter rule implementation | | `src/Bicep.Core/CoreResources.resx` | Resource strings for description and messages | | `src/Bicep.Core/CoreResources.Designer.cs` | Auto-generated resource accessors | | `src/vscode-bicep/schemas/bicepconfig.schema.json` | Schema entry for configuring the rule | | `src/Bicep.Core.UnitTests/.../UseRecognizedResourceTypeRuleTests.cs` | Unit tests | ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/19303) Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #19172
Adds a new linter rule
use-recognized-resource-typethat emits a warning when areferenceorlist*function call uses a resource type that is not recognized by Bicep's type system.What the rule does
reference()andlist*()function callsresourceId()wrapper callsApiVersionProviderPotentialCodeIssuescategory)Example
Files changed
src/Bicep.Core/Analyzers/Linter/Rules/UseRecognizedResourceTypeRule.cssrc/Bicep.Core/CoreResources.resxsrc/Bicep.Core/CoreResources.Designer.cssrc/vscode-bicep/schemas/bicepconfig.schema.jsonsrc/Bicep.Core.UnitTests/.../UseRecognizedResourceTypeRuleTests.csMicrosoft Reviewers: Open in CodeFlow