Linter 規則 - 簡化 JSON null
此規則會尋找 json('null')
。
Linter 規則程式碼
使用 Bicep 設定檔中的下列值來自訂規則設定:
simplify-json-null
解決方案
下列範例會導致此測試失敗,因為已使用 json('null')
:
@description('The name of the API Management service instance')
param apiManagementServiceName string = 'apiservice${uniqueString(resourceGroup().id)}'
@description('The email address of the owner of the service')
@minLength(1)
param publisherEmail string
@description('The name of the owner of the service')
@minLength(1)
param publisherName string
@description('The pricing tier of this API Management service')
@allowed([
'Premium'
])
param sku string = 'Premium'
@description('The instance size of this API Management service.')
param skuCount int = 3
@description('Location for all resources.')
param location string = resourceGroup().location
@description('Zone numbers e.g. 1,2,3.')
param availabilityZones array = [
'1'
'2'
'3'
]
resource apiManagementService 'Microsoft.ApiManagement/service@2023-05-01-preview' = {
name: apiManagementServiceName
location: location
zones: ((length(availabilityZones) == 0) ? json('null') : availabilityZones)
sku: {
name: sku
capacity: skuCount
}
identity: {
type: 'SystemAssigned'
}
properties: {
publisherEmail: publisherEmail
publisherName: publisherName
}
}
您可以將 json('null')
取代為 null
來簡化語法:
@description('The name of the API Management service instance')
param apiManagementServiceName string = 'apiservice${uniqueString(resourceGroup().id)}'
@description('The email address of the owner of the service')
@minLength(1)
param publisherEmail string
@description('The name of the owner of the service')
@minLength(1)
param publisherName string
@description('The pricing tier of this API Management service')
@allowed([
'Premium'
])
param sku string = 'Premium'
@description('The instance size of this API Management service.')
param skuCount int = 3
@description('Location for all resources.')
param location string = resourceGroup().location
@description('Zone numbers e.g. 1,2,3.')
param availabilityZones array = [
'1'
'2'
'3'
]
resource apiManagementService 'Microsoft.ApiManagement/service@2023-05-01-preview' = {
name: apiManagementServiceName
location: location
zones: ((length(availabilityZones) == 0) ? null : availabilityZones)
sku: {
name: sku
capacity: skuCount
}
identity: {
type: 'SystemAssigned'
}
properties: {
publisherEmail: publisherEmail
publisherName: publisherName
}
}
您可以選取快速修正來簡化語法,如下列螢幕擷取畫面所示:
下一步
如需 Linter 的詳細資訊,請參閱使用 Bicep Linter。