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];
error[js/noDelete]: This is an unexpected use of the delete operator.
┌─ js/noDelete.js:2:1
│
2 │ delete arr[0][2];
│ ^^^^^^^^^^^^^^^^
Suggested fix: Replace with undefined assignment
| @@ -1,2 +1,2 @@
0 0 | const arr = [['a','b','c'], [1, 2, 3]];
1 | - delete arr[0][2];
1 | + arr[0][2] = undefined;
const obj = {a: {b: {c: 123}}};
delete obj.a.b.c;
error[js/noDelete]: This is an unexpected use of the delete operator.
┌─ js/noDelete.js:2:1
│
2 │ delete obj.a.b.c;
│ ^^^^^^^^^^^^^^^^
Suggested fix: Replace with undefined assignment
| @@ -1,2 +1,2 @@
0 0 | const obj = {a: {b: {c: 123}}};
1 | - delete obj.a.b.c;
1 | + obj.a.b.c = undefined;
Valid
const foo = new Set([1,2,3]);
foo.delete(1);