Aturan linter - menyederhanakan JSON null

Aturan ini menemukan json('null').

Kode aturan Linter

Gunakan nilai berikut pada file konfigurasi Bicep untuk menyesuaikan pengaturan aturan:

simplify-json-null

Solusi

Contoh berikut gagal dalam pengujian ini karena json('null') digunakan:

@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
  }
}

Anda dapat menyederhanakan sintaks dengan mengganti json('null') dengan 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
  }
}

Anda dapat menyederhanakan sintaks dengan memilih Perbaikan Cepat seperti yang ditunjukkan pada cuplikan layar berikut:

Cuplikan layar penyederhanaan perbaikan cepat JSON null.

Langkah berikutnya

Untuk informasi selengkapnya tentang linter, lihat Menggunakan linter Bicep.