src/content/docs/linter/rules/no-unused-imports.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.3.0` - Diagnostic Category: [`lint/correctness/noUnusedImports`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - Sources: - Same as [`unused-imports/no-unused-imports`](https://github.com/sweepline/eslint-plugin-unused-imports/blob/master/docs/rules/no-unused-imports.md){
"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';
import * as A from 'mod';
import { type A, B } from 'mod';
export { B }
// Header comment
import /*inner comment */ A from 'mod'; // Associated comment
// Another header comment
import {
// A's header comment
type A, // A's comment
// B's header comment
B,
} from 'mod';
export { 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';