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
code-block.js:1:8 lint/correct... > 1 │ import A from ‘mod’; │ ^ 2 │ ℹ Unused imports might be the result of an incomplete refactoring. ℹ Unsafe fix: Remove the unused imports....
🌐
npm
npmjs.com › package › eslint-plugin-unused-imports
eslint-plugin-unused-imports - npm
If writing react code you need to install eslint-plugin-react and enable the two rules react/jsx-uses-react and react/jsx-uses-vars. Otherwise all imports for components will be reported unused. You'll first need to install ESLint (and @typescript-eslint if using typescript): ... Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-unused-imports globally.
      » npm install eslint-plugin-unused-imports
    
Published   Feb 09, 2026
Version   4.4.1
Author   Mikkel Holmer Pedersen
🌐
GitHub
github.com › import-js › eslint-plugin-import › issues › 1608
Definition for rule 'import/no-unused-modules' was not found · Issue #1608 · import-js/eslint-plugin-import
October 16, 2019 - using "eslint-plugin-import": "^2.13.0", Added this rule in my .eslintrc "import/no-unused-modules": [1, {"unusedExports": true}], I got this error on all files 1:1 warning Definition for rule 'import/no-unused-modules' was not found imp...
Author   fr-irene
🌐
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 › 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.
import unusedImports from "eslint-plugin-unused-imports"; export default [{ plugins: { "unused-imports": unusedImports, }, rules: { "no-unused-vars": "off", // or "@typescript-eslint/no-unused-vars": "off", "unused-imports/no-unused-imports": "error", "unused-imports/no-unused-vars": [ "warn", { "vars": "all", "varsIgnorePattern": "^_", "args": "after-used", "argsIgnorePattern": "^_", }, ] } }];
Starred by 615 users
Forked by 27 users
Languages   TypeScript 98.2% | JavaScript 1.8% | TypeScript 98.2% | JavaScript 1.8%
🌐
GitHub
github.com › typescript-eslint › typescript-eslint › issues › 379
1:1 error Definition for rule '@typescript-eslint/no-unused-vars' was not found @typescript-eslint/no-unused-vars · Issue #379 · typescript-eslint/typescript-eslint
March 27, 2019 - I have the following eslintrc.json: { "parser": "@typescript-eslint/parser", "extends": [ "prettier", "plugin:prettier/recommended", "react-app" ], "rules": { "no-unused-vars": "off", "@typescript-eslint/no-unused-vars": "error" }, "pars...
Author   jordyvandomselaar
🌐
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 · By default, this check is skipped for __init__.py files, as they often contain imports from submodules for the convenience of end users. While these imports are not used within __init__.py, they serve the purpose of providing intuitive ...
Find elsewhere
🌐
Quora
quora.com › I-use-PyCharm-as-my-IDE-but-there-is-an-annoying-warning-in-it-it-says-unused-import-statement-when-I-import-a-library-from-Python-Is-there-a-solution
I use PyCharm as my IDE, but there is an annoying warning in it, it says 'unused import statement' when I import a library from Python. Is there a solution? - Quora
Answer (1 of 4): It means you are importing some stuffs, but not using them. You should first take it as a warning and check your code to see why are you importing it at all. Likely, your code will work as you desire without that specific import ...
🌐
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 › import-js › eslint-plugin-import › blob › main › docs › rules › no-unused-modules.md
eslint-plugin-import/docs/rules/no-unused-modules.md at main · import-js/eslint-plugin-import
individual exports not being statically imported or requireed from other modules in the same project · dynamic imports are supported if argument is a literal string · In order for this plugin to work, at least one of the options missingExports ...
Author   import-js
🌐
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. In addition to avoiding compilation errors, this rule may still be useful if you wish to have tslint ...
🌐
Scalacenter
scalacenter.github.io › scalafix › docs › rules › RemoveUnused.html
RemoveUnused · Scalafix
$ scala3 -W ... -Wunused Enable or disable specific `unused` warnings Choices : - nowarn, - all, - imports : Warn if an import selector is not referenced., - privates : Warn if a private member is unused, - locals : Warn if a local definition is unused, - explicits : Warn if an explicit parameter is unused, - implicits : Warn if an implicit parameter is unused, - params : Enable -Wunused:explicits,implicits, - patvars : Warn if a variable bound in a pattern is unused, - linted : Enable -Wunused:imports,privates,locals,implicits, - strict-no-implicit-warn : Same as -Wunused:import, only for imports of explicit named members.
🌐
GitHub
github.com › oxc-project › oxc › issues › 13706
Add no-unused-imports rule · Issue #13706 · oxc-project/oxc
May 28, 2025 - In contrast, a dedicated no-unused-imports rule would focus solely on imports that are never referenced in the code. Because unused imports are always unnecessary, they can be safely removed.
Author   cjnoname
🌐
GitHub
github.com › sweepline › eslint-plugin-unused-imports › issues › 66
no-unused-imports rule fails to detect certain unused interfaces · Issue #66 · sweepline/eslint-plugin-unused-imports
(The typings used in my environment are defined in @types/react@18.0.28.) import { FocusEvent, useCallback, useEffect, useRef, useState } from "react"; The rule recognizes the four imported functions as unused, but not the interface:
🌐
GitHub
github.com › biomejs › biome › discussions › 3341
Clean up unused imports · biomejs/biome · Discussion #3341
I am requesting the feature of automatically removing unused imports from files. Not just empty/useless imports · 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