noDelete (since v0.7.0)
This rule is recommended by Rome.
Disallow the use of the delete
operator
Examples
Invalid
const arr = [['a','b','c'], [1, 2, 3]];
delete arr[0][2];
performance/noDelete.js:2:1 lint/performance/noDelete FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This is an unexpected use of the delete operator.
1 │ const arr = [['a','b','c'], [1, 2, 3]];
> 2 │ delete arr[0][2];
│ ^^^^^^^^^^^^^^^^
3 │
ℹ Suggested fix: Replace with undefined assignment
1 1 │ const arr = [['a','b','c'], [1, 2, 3]];
2 │ - delete·arr[0][2];
2 │ + arr[0][2]·=·undefined;
3 3 │
const obj = {a: {b: {c: 123}}};
delete obj.a.b.c;
performance/noDelete.js:2:1 lint/performance/noDelete FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This is an unexpected use of the delete operator.
1 │ const obj = {a: {b: {c: 123}}};
> 2 │ delete obj.a.b.c;
│ ^^^^^^^^^^^^^^^^
3 │
ℹ Suggested fix: Replace with undefined assignment
1 1 │ const obj = {a: {b: {c: 123}}};
2 │ - delete·obj.a.b.c;
2 │ + obj.a.b.c·=·undefined;
3 3 │
Valid
const foo = new Set([1,2,3]);
foo.delete(1);