# no-delete-var

Rule `sonarjs/no-delete-var`. "delete" should be used only with object properties

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

## Linters

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

## Code examples

### Incorrect: the rule reports this

```js
var x  = 1;
delete x;       // Noncompliant

function foo(){
..
}

delete foo;  // Noncompliant
```

### Correct: the rule accepts this

```js
var obj = {
  x:1,
  foo: function(){
  ...
  }
};
delete obj.x;
delete obj.foo;
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/no-delete-var": "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-delete-var](https://lintradar.dev/rules/eslint/no-delete-var.md): Disallow deleting variables
- [sonarjs/no-default-utility-imports](https://lintradar.dev/rules/sonarjs/no-default-utility-imports.md): Default imports from modular utility libraries should not be used
- [sonarjs/no-duplicate-in-composite](https://lintradar.dev/rules/sonarjs/no-duplicate-in-composite.md): Union and intersection types should not include duplicated constituents
- [sonarjs/no-debug-commands-in-ui-tests](https://lintradar.dev/rules/sonarjs/no-debug-commands-in-ui-tests.md): UI test debug commands should not be committed to version control
- [sonarjs/no-duplicate-parameterized-test-case](https://lintradar.dev/rules/sonarjs/no-duplicate-parameterized-test-case.md): Parameterized tests should not contain duplicate test cases
- [sonarjs/no-debounce-throttle-in-render](https://lintradar.dev/rules/sonarjs/no-debounce-throttle-in-render.md): Lodash and Underscore.js debounced or throttled functions should not be recreated on every React render

---

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