bicep icon indicating copy to clipboard operation
bicep copied to clipboard

Providing a way for extension users to enforce linting errors when the type.json schema is not respected

Open GABRIELNGBTUC opened this issue 6 months ago • 1 comments

Is your feature request related to a problem? Please describe.

Whenever an Azure resource has a missing property, an error is returned by the compiler providing the list of properties that should be present.

// Returns BCP035 Error
// The specified "resource" declaration is missing the following required properties: "kind", "location", "name", "sku". If this is a resource type definition inaccuracy, report it using https://aka.ms/bicep-type-issues.
resource storage_res 'Microsoft.Storage/storageAccounts@2024-01-01' = {
}

However, when using extension types, the error becomes a warning which could easily be ignored or missed by the user when not using an extension like Error Lens in VSCode.

extension kubernetes with {
  namespace: ''
  kubeConfig: 'ddd'
}

// Returns BCP035 Warning
// The specified "resource" declaration is missing the following required properties: "metadata". If this is a resource type definition inaccuracy, report it using https://aka.ms/bicep-type-issues.
// Yellow squiggly lines needs to be hovered or the problem tab needs to be opened and read
resource namespace_res 'core/Namespace@v1'  = {

}

Allowing the compilation of this bicep file that does not respect the type schema will often lead to runtime errors and loss of development time to fix the issue after the fact.

Describe the solution you'd like There should be a way to enforce that required properties on extension types should be present to allow the compilation of the bicep file.

Either through the original compiler error by upgrading it's level to error so that it is in line with Azure resources.

Or through a new linter rule with a default error level to allow users who are happy with the current behaviour to disable the enforcement.

Edit: After doing some tests on my own extensions, I noticed that the problem only affects the MsGraph and Kubernetes extensions. So perhaps this is actually a problem specific to only those two extensions?

Edit2: It seems that the behaviour is not consistent within resources of the same extension. These three resource types are within the same extension and only the third does not return an error for the missing required properties

Image

GABRIELNGBTUC avatar Jun 26 '25 07:06 GABRIELNGBTUC

This also applies to BCP416 The supplied string does not match the expected pattern of regexPatternHere..

An extension author can specify a pattern that a string should follow. But while this triggers an error when the pattern is not respected inside the extension configuration. Not respecting the pattern inside resource declarations only results in a warning.

GABRIELNGBTUC avatar Jun 27 '25 08:06 GABRIELNGBTUC