no-delete-var

Disallow delete on variables

warn by default

delete removes a property from an object. It doesn't remove a variable. On a variable declared with var, let or const, it does nothing and returns false.

In strict mode and in modules this is already a syntax error. The rule catches it in the scripts where it isn't, such as a .cjs file without "use strict".

This rule is on by default.

Configure#

On by default as a warning. To turn it off:

bunfig.toml
[lint.rules]
"no-delete-var" = "off" # or "error"

Examples#

Reported, in a .cjs file:

legacy.cjs1 problem
var session = createSession();
delete session;
example.jsNo problems
var session = createSession();
session = undefined;

delete cache.session;