{"record":{"id":"0274fb46e3a6ef2f","repo":"oxc-project/oxc","slug":"variables-should-not-be-deleted","errorCode":null,"errorMessage":"Variables should not be deleted","messagePattern":"Variables should not be deleted","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_delete_var.rs","lineNumber":10,"sourceCode":"use oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse oxc_syntax::operator::UnaryOperator;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn no_delete_var_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Variables should not be deleted\")\n        .with_help(\"Assign `undefined` to the variable instead of using `delete`. The `delete` operator is intended for removing properties from objects, not for variables.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoDeleteVar;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// The purpose of the `delete` operator is to remove a property from an\n    /// object.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Using the `delete` operator on a variable might lead to unexpected\n    /// behavior.\n    ///","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_delete_var.rs#L1-L28","documentation":"This diagnostic comes from the `no_delete_var` rule in oxlint. The `delete` operator removes a property from an object; it cannot remove a variable binding. The rule reports a `delete` unary expression whose operand is a variable reference. In strict mode code, such a `delete` is an early syntax error, so the parser rejects it before lint even runs.","triggerScenarios":"A `delete` unary operator applied to an identifier that names a variable: `delete myVar;` in a sloppy-mode script. The rule matches `UnaryOperator::Delete` with an identifier operand.","commonSituations":"A developer with C or Python background writes `delete x` to free memory. Code copied from old pre-strict scripts. A refactor moves code into an ES module, where strict mode makes the line a hard parse error.","solutions":["Assign `undefined` when only the value must be gone: `x = undefined;`.","Move the data into an object and delete the property: `delete obj.x;`.","Put the code in a block or function scope so the variable goes out of scope on its own.","Suppress once with `// oxlint-disable-next-line no-delete-var` in non-strict legacy code."],"exampleFix":"// before\nlet tmp = compute(user);\ndelete tmp;\n\n// after\nlet tmp = compute(user);\ntmp = undefined;","handlingStrategy":"validation","validationCode":"// scan sources before lint\nconst bad = /(^|[^.\\w])delete\\s+[A-Za-z_$][\\w$]*\\s*;/.exec(src);\nif (bad) throw new Error('delete on a variable: ' + bad[0]);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use `delete` only on object properties.","Prefer block or function scope over manual cleanup.","Keep files in strict mode (ES modules are strict) so the parser rejects this pattern early."],"tags":["javascript","eslint","lint","memory","strict-mode"],"backgroundTag":"lint-delete-variable","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}