no-unused-imports
Reports import specifiers that are never used.
Rule details Problem
Section titled “Rule details ”ProblemThis rule checks default imports, namespace imports, and named imports. When a binding is never referenced, it reports
it and can remove the unused specifier with --fix.
By default, references inside JSDoc also count as usage. Bare side-effect imports like import "./init"; are ignored.
Options
Section titled “Options”| Option | Type | Default | What it does |
|---|---|---|---|
checkJSDoc | boolean | true | Counts supported JSDoc references as usage |
Configuration
Section titled “Configuration”import ceaseNonsense from "eslint-plugin-cease-nonsense";
export default [ { plugins: { "cease-nonsense": ceaseNonsense, }, rules: { "cease-nonsense/no-unused-imports": ["error", { checkJSDoc: true }], }, },];Examples
Section titled “Examples” Incorrect
import { unusedFunction, usedFunction } from "./utils";import { AnotherUnused } from "./types";
usedFunction(); Correct
import { usedFunction } from "./utils";import { anotherUsedFunction } from "./more-utils";
/** * @see {anotherUsedFunction} */usedFunction();Related rules
Section titled “Related rules” no-commented-code Removes dead code left in comments
ESLint: no-unused-vars Base rule for unused variables