# unused-import

Rule `sonarjs/unused-import`. Unnecessary imports should be removed

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: yes
- Autofix: yes, in at least one linter
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1377 by reach, #678 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/unused-import` | yes | suggestion | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-1128/) |

## Code examples

### Incorrect: the rule reports this

```js
import A from 'a';      // Noncompliant, A isn't used
import { B1 } from 'b';

console.log(B1);
```

### Correct: the rule accepts this

```js
import { B1 } from 'b';

console.log(B1);
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "sonarjs/unused-import": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/todo-tag](https://lintradar.dev/rules/sonarjs/todo-tag.md): Track uses of "TODO" tags
- [sonarjs/unused-named-groups](https://lintradar.dev/rules/sonarjs/unused-named-groups.md): Names of regular expressions named groups should be used
- [sonarjs/testing-library-query-assertion](https://lintradar.dev/rules/sonarjs/testing-library-query-assertion.md): Testing Library queries should match presence assertions
- [sonarjs/unverified-certificate](https://lintradar.dev/rules/sonarjs/unverified-certificate.md): Server certificates should be verified during SSL/TLS connections
- [sonarjs/testing-library-prefer-query-by-disappearance](https://lintradar.dev/rules/sonarjs/testing-library-prefer-query-by-disappearance.md): Testing Library disappearance waits should use non-throwing queries
- [sonarjs/unverified-hostname](https://lintradar.dev/rules/sonarjs/unverified-hostname.md): Server hostnames should be verified during SSL/TLS connections

---

Web page: https://lintradar.dev/rules/sonarjs/unused-import. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
