Skip to content

noUnusedImports

biome.json
{
"linter": {
"rules": {
"correctness": {
"noUnusedImports": "error"
}
}
}
}

Disallow unused imports.

Unused imports might be the result of an incomplete refactoring. The code fix can remove comments associated with an import. See the last invalid example.

Note that the leading trivia, e.g., comments or newlines preceding the unused imports will also be removed. So that comment directives like @ts-expect-error won’t be transferred to a wrong place.

This rule respects the jsxRuntime setting and will make an exception for React globals if it is set to "reactClassic".

import A from 'mod';
code-block.js:1:8 lint/correctness/noUnusedImports  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This import is unused.

> 1 │ import A from ‘mod’;
^
2 │

Unused imports might be the result of an incomplete refactoring.

Unsafe fix: Remove the unused imports.

1 │ import·A·from·mod;
--------------------
import * as A from 'mod';
code-block.js:1:13 lint/correctness/noUnusedImports  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This import is unused.

> 1 │ import * as A from ‘mod’;
^
2 │

Unused imports might be the result of an incomplete refactoring.

Unsafe fix: Remove the unused imports.

1 │ import·*·as·A·from·mod;
-------------------------
import { type A, B } from 'mod';
export { B }
code-block.ts:1:10 lint/correctness/noUnusedImports  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Several of these imports are unused.

> 1 │ import { type A, B } from ‘mod’;
^^^^^^
2 │
3 │ export { B }

Unused imports might be the result of an incomplete refactoring.

Unsafe fix: Remove the unused imports.

1 │ import·{·type·A,·B·}·from·‘mod’;
--------
// Header comment
import /*inner comment */ A from 'mod'; // Associated comment
code-block.ts:2:27 lint/correctness/noUnusedImports  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This import is unused.

1 │ // Header comment
> 2 │ import /*inner comment */ A from ‘mod’; // Associated comment
^
3 │

Unused imports might be the result of an incomplete refactoring.

Unsafe fix: Remove the unused imports.

1 - //·Header·comment
2 - import·/*inner·comment·*/·A·from·mod;·//·Associated·comment
1+
3 2

// Another header comment
import {
// A's header comment
type A, // A's comment
// B's header comment
B,
} from 'mod';
export { B }
code-block.ts:4:5 lint/correctness/noUnusedImports  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Several of these imports are unused.

2 │ import {
3 │ // A’s header comment
> 4 │ type A, // A’s comment
^^^^^^
5 │ // B’s header comment
6 │ B,

Unused imports might be the result of an incomplete refactoring.

Unsafe fix: Remove the unused imports.

1 1 // Another header comment
2 2 import {
3 - ····//·As·header·comment
4 - ····type·A,·//·As·comment
5 3 // B’s header comment
6 4 B,

import { A, type B } from 'mod';
function f(arg: B): A {
return new A(arg);
}

One notable exception is when the import is intended to be used for type augmentation.

import type {} from '@mui/lab/themeAugmentation';