Using unused-imports plugin and unused-imports/no-unused-imports-ts rule, eslint --fix will remove the imports.

Here is an example repo which --fix removes the unused imports.

https://github.com/moshfeu/eslint-ts-unused-imports

Setup

yarn add -D eslint-plugin-unused-imports
// eslint.config.js

import tseslint from "typescript-eslint";
import unusedImports from "eslint-plugin-unused-imports";

export default tseslint.config(
  {
    plugins: {
      "unused-imports": unusedImports,
    },
    rules: {
      "unused-imports/no-unused-imports": "warn",
    },
  }
);

Old answer

eslint has a built-in fix option.

eslint ... --fix

If rules contains no-unused-vars, eslint will "fix" the unused import by removing them (along with other auto fixes).

Answer from Mosh Feu on Stack Overflow
🌐
Biome
biomejs.dev › linter › rules › no-unused-imports
noUnusedImports | Biome
> 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’; │ ------------------------- ... ...
🌐
npm
npmjs.com › package › eslint-plugin-unused-imports
eslint-plugin-unused-imports - npm
Find and remove unused es6 module imports. It works by splitting up the no-unused-vars rule depending on it being an import statement in the AST and providing an autofix rule to remove the nodes if they are imports.
      » npm install eslint-plugin-unused-imports
    
Published   Feb 09, 2026
Version   4.4.1
Author   Mikkel Holmer Pedersen
🌐
GitHub
github.com › sweepline › eslint-plugin-unused-imports
GitHub - sweepline/eslint-plugin-unused-imports: Package to separate no-unused-vars and no-unused-imports for eslint as well as providing an autofixer for the latter.
Find and remove unused es6 module imports. It works by splitting up the no-unused-vars rule depending on it being an import statement in the AST and providing an autofix rule to remove the nodes if they are imports.
Starred by 615 users
Forked by 27 users
Languages   TypeScript 98.2% | JavaScript 1.8% | TypeScript 98.2% | JavaScript 1.8%
🌐
Pylint
pylint.readthedocs.io › en › latest › user_guide › messages › warning › unused-import.html
unused-import / W0611 - Pylint 4.1.0-dev0 documentation
Used when an imported module or variable is not used. ... from logging import getLogger from pathlib import Path # [unused-import] LOGGER = getLogger(__name__)
🌐
Simon Dosda
simondosda.github.io › posts › 2021-05-10-eslint-imports.html
Automatically Remove Unused Imports From Your JS Projects | Simon Dosda
July 6, 2021 - The number of errors should be superior to 0 unless you don’t have any unused imports in your project. If that’s the case, add some for the sake of this exercise ;). Next, run npx eslint <project-directory> --fix and…voilà! There should not be any unused import in your code anymore.
🌐
GitHub
github.com › microsoft › vscode-eslint › issues › 1767
No error report in editor on "unused-imports/no-unused-imports" · Issue #1767 · microsoft/vscode-eslint
January 18, 2024 - Hi! Unfortunately, plugin is not showing and not fixing errors in editor for "unused-imports/no-unused-imports" rule. If I run npm script "eslint .", I will see these errors in a terminal. Also, I can see these errors in WebStorm IDE, bu...
Author   AlexMarlow25
🌐
TypeScript ESlint
typescript-eslint.io › rules › no-unused-vars
no-unused-vars | typescript-eslint
When this is set to false (the default) the rule will only provide suggestion fixers for unused imports. When this is set to true the rule will provide an automatic fixer. Note: If all specifiers of an import declaration are unused then the entire import declaration will be removed.
Find elsewhere
🌐
Symfony
cs.symfony.com › doc › rules › import › no_unused_imports.html
Rule no_unused_imports - PHP Coding Standards Fixer
Install now · Unused use statements must be removed. --- Original +++ New <?php use \DateTime; -use \Exception; new DateTime(); The rule is part of the following rule sets: @PhpCsFixer · @Symfony · Fixer class: PhpCsFixer\Fixer\Import\NoUnusedImportsFixer ·
🌐
Astral
docs.astral.sh › ruff › rules › unused-import
unused-import (F401) | Ruff
This can result in both different and more import statements being marked as unused. ... then both statements are marked as unused under preview, whereas only the second is marked as unused under stable behavior. ... then a diagnostic will be emitted for the second line under preview, whereas no diagnostic is emitted under stable behavior.
🌐
GitHub
github.com › typescript-eslint › typescript-eslint › issues › 3092
[@typescript-eslint/no-unused-vars] Unused import. · Issue #3092 · typescript-eslint/typescript-eslint
February 22, 2021 - TypeScript detects it as in-use. Generally unused imports are grayed out (opacity about 0.5) and marked as unused, even from TypeScript. So this should be reported from the linter.
Author   infacto
🌐
GitHub
github.com › pinterest › ktlint › issues › 3038
Do not run `no-unused-imports` rule by default · Issue #3038 · pinterest/ktlint
July 5, 2025 - The no-unused-imports rules tries to detect imports that are not used. Over the years, it has been proven difficult for KtLint to prevent false positive detections of unused imports.
Author   paul-dingemans
🌐
GitHub
github.com › eslint › eslint › discussions › 18494
Add optional feature to remove unused imports · eslint/eslint · Discussion #18494
The reason i have ended up monkey patching is because I actually use the built-in no-unused-vars rule and then split it up into two rules. One rule that has an autofixer for removing said variable and one that is just the built-in rule. This is split up based on the AST type being "ImportSpecifier", "ImportDefaultSpecifier" or "ImportNamespaceSpecifier".
Author   eslint
🌐
Palantir
palantir.github.io › tslint › rules › no-unused-variable
Rule: no-unused-variable
Disallows unused imports, variables, functions and private class members. Similar to tsc’s –noUnusedParameters and –noUnusedLocals options, but does not interrupt code compilation.
🌐
GitHub
github.com › biomejs › biome › discussions › 3341
Clean up unused imports · biomejs/biome · Discussion #3341
When I'm coding, I have auto import that works great, now just need deletions of code blocks to be cleaned up. The efficiency lose is too great having to go back up to the top of the file to remove code. I'm aware of the linter action https://biomejs.dev/linter/rules/no-unused-imports/
Author   biomejs
🌐
Checkstyle
checkstyle.sourceforge.io › checks › imports › unusedimports.html
UnusedImports – checkstyle
Checks for unused import statements. An import statement is considered unused if: It is not referenced in the file.