Skip to main content

js/noDelete

disallow the use of the delete operator

Examples

Invalid

const arr = [['a','b','c'], [1, 2, 3]];
delete arr[0][2];

 file.ts:2 lint/js/noDelete  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  This is an unexpected use of the delete operator.

    1const arr = [['a','b','c'], [1, 2, 3]];
  > 2delete arr[0][2];
     ^^^^^^^^^^^^^^^^

  Safe fix

  - delete·arr[0][2]
  + arr[0][2]·=·undefined


const obj = {a: {b: {c: 123}}};
delete obj.a.b.c;

 file.ts:2 lint/js/noDelete  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  This is an unexpected use of the delete operator.

    1const obj = {a: {b: {c: 123}}};
  > 2delete obj.a.b.c;
     ^^^^^^^^^^^^^^^^

  Safe fix

  - delete·obj.a.b.c
  + obj.a.b.c·=·undefined

Valid

const foo = new Set([1,2,3]);
foo.delete(1);