Skip to content

Commit 4f352a3

Browse files
committed
Linter - no unused imports
1 parent 313be25 commit 4f352a3

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

articles/azure-resource-manager/bicep/bicep-config-linter.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ The following example shows the rules that are available for configuration.
7575
"no-unused-existing-resources": {
7676
"level": "warning"
7777
},
78+
"no-unused-imports": {
79+
"level": "error"
80+
},
7881
"no-unused-params": {
7982
"level": "warning"
8083
},

articles/azure-resource-manager/bicep/bicep-core-diagnostics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.custom:
77
- devx-track-bicep
88
- devx-track-arm-template
99
- build-2025
10-
ms.date: 05/20/2025
10+
ms.date: 06/06/2025
1111
---
1212

1313
# Bicep core diagnostics
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: Linter rule - no unused imports
3+
description: Linter rule - no unused imports
4+
ms.topic: reference
5+
ms.custom: devx-track-bicep
6+
ms.date: 06/06/2025
7+
---
8+
9+
# Linter rule - no unused imports
10+
11+
This rule finds [import alias](./bicep-import.md#import-variables-types-and-functions) that aren't referenced anywhere in the Bicep file.
12+
13+
## Linter rule code
14+
15+
Use the following value in the [Bicep configuration file](bicep-config-linter.md) to customize rule settings:
16+
17+
`no-unused-imports`
18+
19+
## Solution
20+
21+
To reduce confusion in your Bicep file, delete any imports that are defined but not used. This test finds all imports that aren't used anywhere in the template.
22+
23+
The following example fails this test because `myImports` and `myObjectType` are not used in the Bicep file:
24+
25+
```bicep
26+
import * as myImports from 'exports.bicep'
27+
import {myObjectType, sayHello} from 'exports.bicep'
28+
29+
output greeting string = sayHello('Bicep user')
30+
```
31+
32+
You can fix it by removing and updating the `import` statements.
33+
34+
```bicep
35+
import {sayHello} from 'exports.bicep'
36+
37+
output greeting string = sayHello('Bicep user')
38+
```
39+
40+
Use **Quick Fix** to remove the unused imports:
41+
42+
:::image type="content" source="./media/linter-rule-no-unused-imports/linter-rule-no-unused-imports-quick-fix.png" alt-text="A screenshot of using Quick Fix for the no-unused-variables linter rule.":::
43+
44+
## Next steps
45+
46+
For more information about the linter, see [Use Bicep linter](./linter.md).

articles/azure-resource-manager/bicep/linter.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Use Bicep linter
33
description: Learn how to use Bicep linter.
44
ms.topic: how-to
55
ms.custom: devx-track-bicep
6-
ms.date: 02/12/2025
6+
ms.date: 06/06/2025
77
---
88

99
# Use Bicep linter
@@ -35,6 +35,7 @@ The default set of linter rules is minimal and taken from [arm-ttk test cases](.
3535
- [no-loc-expr-outside-params](./linter-rule-no-loc-expr-outside-params.md)
3636
- [no-unnecessary-dependson](./linter-rule-no-unnecessary-dependson.md)
3737
- [no-unused-existing-resources](./linter-rule-no-unused-existing-resources.md)
38+
- [no-unused-imports](./linter-rule-no-unused-imports.md)
3839
- [no-unused-params](./linter-rule-no-unused-parameters.md)
3940
- [no-unused-vars](./linter-rule-no-unused-variables.md)
4041
- [outputs-should-not-contain-secrets](./linter-rule-outputs-should-not-contain-secrets.md)
@@ -57,7 +58,7 @@ The default set of linter rules is minimal and taken from [arm-ttk test cases](.
5758
- [use-stable-vm-image](./linter-rule-use-stable-vm-image.md)
5859
- [what-if-short-circuiting](./linter-rule-what-if-short-circuiting.md)
5960

60-
You can customize how the linter rules are applied. To overwrite the default settings, add a **bicepconfig.json** file and apply custom settings. For more information about applying those settings, see [Add custom settings in the Bicep config file](bicep-config-linter.md).
61+
You can enable or disable all linter rules and control how they are applied using a configuration file. To override the default behavior, create a **bicepconfig.json** file with your custom settings. For more information about applying those settings, see [Add custom settings in the Bicep config file](bicep-config-linter.md).
6162

6263
## Use in Visual Studio Code
6364

Loading

0 commit comments

Comments
 (0)