Skip to content

noUnusedImports (since v1.3.0)

Diagnostic Category: lint/nursery/noUnusedImports

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.

import A from 'mod';
nursery/noUnusedImports.js:1:8 lint/nursery/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 import.
  
    1  - import·A·from·'mod';
    2  - 
  
import * as A from 'mod';
nursery/noUnusedImports.js:1:13 lint/nursery/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 import.
  
    1  - import·*·as·A·from·'mod';
    2  - 
  
import { type A, B } from 'mod';
export { B }
nursery/noUnusedImports.js:1:15 lint/nursery/noUnusedImports  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   This import is 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 import.
  
    1 │ import·{·type·A,·B·}·from·'mod';
           --------               
// 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 }
nursery/noUnusedImports.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
  
import { A, type B } from 'mod';
function f(arg: B): A {
return new A(arg);
}