Правило Linter — упрощение значения JSON NULL
Это правило находит json('null')
.
Код правила анализатора кода
Для настройки параметров правил укажите в файле конфигурации 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
}
}
Чтобы упростить синтаксис, нажмите кнопку "Быстрое исправление ", как показано на следующем снимок экрана:
Следующие шаги
Дополнительные сведения об анализаторе кода Bicep см. в разделе Использование анализатора кода Bicep.