{"record":{"id":"50b37afdeeabf24f","repo":"oxc-project/oxc","slug":"prefer-childnode-remove-over-parentnode-remov","errorCode":null,"errorMessage":"Prefer `childNode.remove()` over `parentNode.removeChild(childNode)`.","messagePattern":"Prefer `childNode\\.remove\\(\\)` over `parentNode\\.removeChild\\(childNode\\)`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/prefer_dom_node_remove.rs","lineNumber":14,"sourceCode":"use oxc_ast::{AstKind, ast::Expression};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{\n    AstNode,\n    ast_util::{call_expr_method_callee_info, is_method_call},\n    context::LintContext,\n    rule::Rule,\n};\n\nfn prefer_dom_node_remove_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prefer `childNode.remove()` over `parentNode.removeChild(childNode)`.\")\n        .with_help(\"Replace `parentNode.removeChild(childNode)` with `childNode.remove()`.\")\n        .with_label(span)\n        .with_note(\"https://developer.mozilla.org/en-US/docs/Web/API/Element/remove\")\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferDomNodeRemove;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Prefers the use of `child.remove()` over `parentNode.removeChild(child)`.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// The DOM function [`Node#remove()`](https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove) is preferred\n    /// over the indirect removal of an object with [`Node#removeChild()`](https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild).\n    ///","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_remove.rs#L1-L32","documentation":"Diagnostic from the unicorn/prefer-dom-node-remove lint rule. It fires when a call matches `parentNode.removeChild(childNode)` where the parent expression is the same node the child belongs to; the child's own `remove()` method achieves the same effect without naming the parent, and ignores errors when the node is already detached. It is a lint suggestion, not a runtime error.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/prefer_dom_node_remove.rs:14 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace `parentNode.removeChild(childNode)` with `childNode.remove()`","Apply the rule's auto-fix, which rewrites the call to `childNode.remove()`","Verify the parent expression was indeed the child's direct parent before rewriting"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}