Edit

Share via


Linter rule - no unused imports

This rule finds import alias that aren't referenced anywhere in the Bicep file.

Linter rule code

Use the following value in the Bicep configuration file to customize rule settings:

no-unused-imports

Solution

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.

The following example fails this test because myImports and myObjectType are not used in the Bicep file:

import * as myImports from 'exports.bicep'
import {myObjectType, sayHello} from 'exports.bicep'

output greeting string = sayHello('Bicep user')

You can fix it by removing and updating the import statements.

import {sayHello} from 'exports.bicep'

output greeting string = sayHello('Bicep user')

Use Quick Fix to remove the unused imports:

A screenshot of using Quick Fix for the no-unused-variables linter rule.

Next steps

For more information about the linter, see Use Bicep linter.