Regra do Linter – simplificar o JSON nulo
Esta regra localiza json('null')
.
Código de regra do Linter
Utilize o seguinte valor no ficheiro de configuração do Bicep para personalizar as definições de regras:
simplify-json-null
Solução
O exemplo seguinte falha neste teste porque json('null')
é utilizado:
@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@2022-08-01' = {
name: apiManagementServiceName
location: location
zones: ((length(availabilityZones) == 0) ? json('null') : availabilityZones)
sku: {
name: sku
capacity: skuCount
}
identity: {
type: 'SystemAssigned'
}
properties: {
publisherEmail: publisherEmail
publisherName: publisherName
}
}
Pode simplificar a sintaxe ao substituir json('null')
por 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@2022-08-01' = {
name: apiManagementServiceName
location: location
zones: ((length(availabilityZones) == 0) ? null : availabilityZones)
sku: {
name: sku
capacity: skuCount
}
identity: {
type: 'SystemAssigned'
}
properties: {
publisherEmail: publisherEmail
publisherName: publisherName
}
}
Pode simplificar a sintaxe ao selecionar Correção Rápida , conforme mostrado na seguinte captura de ecrã:
Passos seguintes
Para obter mais informações sobre o linter, veja Utilizar o linter Bicep.