diff --git a/articles/azure-resource-manager/bicep/linter-rule-no-unused-types.md b/articles/azure-resource-manager/bicep/linter-rule-no-unused-types.md new file mode 100644 index 0000000000000..be43fb905b9d0 --- /dev/null +++ b/articles/azure-resource-manager/bicep/linter-rule-no-unused-types.md @@ -0,0 +1,58 @@ +--- +title: Linter rule - no unused types +description: Linter rule - no unused types +ms.topic: reference +ms.custom: devx-track-bicep +ms.date: 07/10/2026 +--- + +# Linter rule - no unused types + +This rule finds [user-defined data types](./user-defined-data-types.md) that aren't referenced anywhere in the Bicep file. + +## Linter rule code + +Use the following value in the [Bicep configuration file](bicep-config-linter.md) to customize rule settings: + +`no-unused-types` + +## Solution + +To reduce confusion in your Bicep file, delete any types that are defined but not used. This test finds all types that aren't used anywhere in the file. + +The following example fails this test because the `unusedType` type is declared but never used: + +```bicep +type unusedType = { + name: string + age: int +} + +param location string = resourceGroup().location + +output deployedToLocation string = location +``` + +You can fix it by removing the unused type declaration, or by referencing the type, for example in a `param` or `output` declaration: + +```bicep +type storageAccountConfigType = { + name: string + sku: string +} + +param storageAccountConfig storageAccountConfigType = { + name: 'mystorageaccount' + sku: 'Standard_LRS' +} + +output configuredName string = storageAccountConfig.name +``` + +Types that are shared with other Bicep files by using the [`@export()`](./user-defined-data-types.md#export) decorator are excluded from this rule, because they're intended to be consumed elsewhere. + +Use **Quick Fix** to remove the unused types. + +## Next steps + +For more information about the linter, see [Use Bicep linter](./linter.md). diff --git a/articles/azure-resource-manager/bicep/linter.md b/articles/azure-resource-manager/bicep/linter.md index a563abbdb81fa..6e044c905aaf0 100644 --- a/articles/azure-resource-manager/bicep/linter.md +++ b/articles/azure-resource-manager/bicep/linter.md @@ -41,6 +41,7 @@ The default set of linter rules is minimal and taken from [arm-ttk test cases](. | [no-unused-existing-resources](./linter-rule-no-unused-existing-resources.md) | warning | | [no-unused-imports](./linter-rule-no-unused-imports.md) | warning | | [no-unused-params](./linter-rule-no-unused-parameters.md) | warning | +| [no-unused-types](./linter-rule-no-unused-types.md) | warning | | [no-unused-vars](./linter-rule-no-unused-variables.md) | warning | | [outputs-should-not-contain-secrets](./linter-rule-outputs-should-not-contain-secrets.md) | warning | | [prefer-interpolation](./linter-rule-prefer-interpolation.md) | warning | diff --git a/articles/azure-resource-manager/bicep/toc.yml b/articles/azure-resource-manager/bicep/toc.yml index 8662fec00c9fd..e58adee1ea893 100644 --- a/articles/azure-resource-manager/bicep/toc.yml +++ b/articles/azure-resource-manager/bicep/toc.yml @@ -534,6 +534,9 @@ items: - name: No unused parameters displayName: linter href: linter-rule-no-unused-parameters.md + - name: No unused types + displayName: linter + href: linter-rule-no-unused-types.md - name: No unused variables displayName: linter href: linter-rule-no-unused-variables.md