قاعدة Linter - استخدام مرجع رمز المورد

تكتشف هذه القاعدة الاستخدامات دون المستوى الأمثل للدالتين referenceو list . بدلا من استدعاء هذه الدالات، يؤدي استخدام مرجع مورد إلى تبسيط بناء الجملة ويسمح ل Bicep بفهم الرسم البياني لتبعية التوزيع بشكل أفضل.

التعليمة البرمجية لقاعدة Linter

استخدم القيمة التالية في ملف تكوين Bicep لتخصيص إعدادات القاعدة:

use-resource-symbol-reference

حل

فشل المثال التالي في هذا الاختبار بسبب استخدامات reference و listKey:

@description('The name of the HDInsight cluster to create.')
param clusterName string

@description('These credentials can be used to submit jobs to the cluster and to log into cluster dashboards.')
param clusterLoginUserName string

@description('The password must be at least 10 characters in length and must contain at least one digit, one upper case letter, one lower case letter, and one non-alphanumeric character except (single-quote, double-quote, backslash, right-bracket, full-stop). Also, the password must not contain 3 consecutive characters from the cluster username or SSH username.')
@minLength(10)
@secure()
param clusterLoginPassword string

@description('Location for all resources.')
param location string = resourceGroup().location

param storageAccountName string = uniqueString(resourceGroup().id)

resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' existing = {
  name: storageAccountName
}

resource cluster 'Microsoft.HDInsight/clusters@2021-06-01' = {
  name: clusterName
  location: location
  properties: {
    clusterVersion: '4.0'
    osType: 'Linux'
    clusterDefinition: {
      kind: 'hbase'
      configurations: {
        gateway: {
          'restAuthCredential.isEnabled': true
          'restAuthCredential.username': clusterLoginUserName
          'restAuthCredential.password': clusterLoginPassword
        }
      }
    }
    storageProfile: {
      storageaccounts: [
        {
          name: replace(replace(reference(storageAccount.id, '2022-09-01').primaryEndpoints.blob, 'https://', ''), '/', '')
          isDefault: true
          container: clusterName
          key: listKeys(storageAccount.id, '2022-09-01').keys[0].value
        }
      ]
    }
  }
}

يمكنك إصلاح المشكلة باستخدام مرجع المورد:

@description('The name of the HDInsight cluster to create.')
param clusterName string

@description('These credentials can be used to submit jobs to the cluster and to log into cluster dashboards.')
param clusterLoginUserName string

@description('The password must be at least 10 characters in length and must contain at least one digit, one upper case letter, one lower case letter, and one non-alphanumeric character except (single-quote, double-quote, backslash, right-bracket, full-stop). Also, the password must not contain 3 consecutive characters from the cluster username or SSH username.')
@minLength(10)
@secure()
param clusterLoginPassword string

@description('Location for all resources.')
param location string = resourceGroup().location

param storageAccountName string = uniqueString(resourceGroup().id)

resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' existing = {
  name: storageAccountName
}

resource cluster 'Microsoft.HDInsight/clusters@2021-06-01' = {
  name: clusterName
  location: location
  properties: {
    clusterVersion: '4.0'
    osType: 'Linux'
    clusterDefinition: {
      kind: 'hbase'
      configurations: {
        gateway: {
          'restAuthCredential.isEnabled': true
          'restAuthCredential.username': clusterLoginUserName
          'restAuthCredential.password': clusterLoginPassword
        }
      }
    }
    storageProfile: {
      storageaccounts: [
        {
          name: replace(replace(storageAccount.properties.primaryEndpoints.blob, 'https://', ''), '/', '')
          isDefault: true
          container: clusterName
          key: storageAccount.listKeys().keys[0].value
        }
      ]
    }
  }
}

يمكنك إصلاح المشكلة تلقائيا عن طريق تحديد Quick Fix كما هو موضح في لقطة الشاشة التالية:

لقطة شاشة لاستخدام الإصلاح السريع لمرجع رمز المورد.

الخطوات التالية

لمزيد من المعلومات حول linter، راجعاستخدام Bicep linter.