variableDeletions
Reports attempting to delete variables with the delete operator.
✅ This rule is included in the ts javascript presets.
The delete operator is only meant to remove properties from objects, not variables.
Attempting to delete a variable in strict mode will cause a syntax error.
In non-strict mode, it will silently fail and return false without actually deleting the variable, which can lead to confusing bugs.
Examples
Section titled “Examples”44AE3F53co44AEco6E72deOptions
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your codebase relies on non-standard behavior that involves deleting variables (which is highly discouraged), you might choose to disable this rule. For example, if you target a legacy runtime with non-standard JavaScript semantics, standard practices may not apply to you.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Deno:
no-delete-var - ESLint:
no-delete-var - Oxlint:
eslint/no-delete-var
