noUnusedImports
Este conteúdo não está disponível em sua língua ainda.
Diagnostic Category: lint/correctness/noUnusedImports
Since: v1.3.0
Sources:
- Same as:
unused-imports/no-unused-imports
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.
Options
Section titled OptionsThis rule respects the jsxRuntime
setting and will make an exception for React globals if it is set to
"reactClassic"
.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-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.
ℹ Safe fix: Remove the unused imports.
1 │ import·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.
ℹ Safe fix: Remove the unused imports.
1 │ import·*·as·A·from·‘mod’;
│ -------------------------
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.
ℹ Safe fix: Remove the unused imports.
1 │ import·{·type·A,·B·}·from·‘mod’;
│ --------
code-block.js:7:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ ‘import { type x ident }’ are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.
5 │ import {
6 │ // A’s header comment
> 7 │ type A, // A’s comment
│ ^^^^^^
8 │ // B’s header comment
9 │ B,
ℹ TypeScript only syntax