src/content/docs/linter/rules/no-delete.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/performance/noDelete`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). ## How to configure ```json title="biome.json" { "linter": { "rules": { "performance": { "noDelete": "error" } } } }## Description
Disallow the use of the `delete` operator.
The `delete` operator enables the removal of a property from an object.
The `delete` operator should be avoided because it [can prevent some optimizations of _JavaScript_ engines](https://webkit.org/blog/10298/inline-caching-delete/).
Moreover, it can lead to unexpected results.
For instance, deleting an array element [does not change the length of the array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete#deleting_array_elements).
The only legitimate use of `delete` is on an object that behaves like a _map_.
To allow this pattern, this rule does not report `delete` on computed properties that are not literal values.
Consider using [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) instead of an object.
## Examples
### Invalid
```js
const arr = [1, 2, 3];
delete arr[0];
const obj = {a: {b: {c: 123}}};
delete obj.a.b.c;
const foo = new Set([1,2,3]);
foo.delete(1);
const map = Object.create(null);
const key = "key"
map[key] = "value"
delete map[key];
let x = 5;
delete f(); // uncovered by this rule.