# no-unused-vars

Rule `sonarjs/no-unused-vars`. Unused local variables and functions should be removed

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1326 by reach, #627 by growth

## Linters

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

## Code examples

### Incorrect: the rule reports this

```js
function numberOfMinutes(hours) {
  var seconds = 0;   // seconds is never used
  return hours * 60;
}
```

### Correct: the rule accepts this

```js
function numberOfMinutes(hours) {
  return hours * 60;
}
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/no-unused-vars": "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

- [eslint/no-unused-vars](https://lintradar.dev/rules/eslint/no-unused-vars.md): Disallow unused variables
- [typescript/no-unused-vars](https://lintradar.dev/rules/typescript/no-unused-vars.md): Disallow unused variables
- [vue/no-unused-vars](https://lintradar.dev/rules/vue/no-unused-vars.md): Disallow unused variable definitions of v-for directives or scope attributes
- [sonarjs/no-unused-collection](https://lintradar.dev/rules/sonarjs/no-unused-collection.md): Collection contents should be used
- [sonarjs/no-use-of-empty-return-value](https://lintradar.dev/rules/sonarjs/no-use-of-empty-return-value.md): The return value of void functions should not be used
- [sonarjs/no-unthrown-error](https://lintradar.dev/rules/sonarjs/no-unthrown-error.md): Errors should not be created without being thrown

---

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