Lint Rules

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];
correctness/noDelete.js:2:1 lint/correctness/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;
correctness/noDelete.js:2:1 lint/correctness/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);