{"record":{"id":"11b1285f0ab101f4","repo":"oxc-project/oxc","slug":"prefer-using-good-method-over-bad-method","errorCode":null,"errorMessage":"Prefer using `{good_method}` over `{bad_method}`.","messagePattern":"Prefer using `(.+?)` over `(.+?)`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/prefer_modern_dom_apis.rs","lineNumber":16,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Argument, Expression},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{AstNode, ast_util::is_method_call, context::LintContext, rule::Rule};\n\nfn prefer_modern_dom_apis_diagnostic(\n    good_method: &str,\n    bad_method: &str,\n    span: Span,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Prefer using `{good_method}` over `{bad_method}`.\"))\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferModernDomApis;\n\nfn get_replacement_for_disallowed_method(method: &str) -> Option<&'static str> {\n    match method {\n        \"replaceChild\" => Some(\"replaceWith\"),\n        \"insertBefore\" => Some(\"before\"),\n        _ => None,\n    }\n}\n\nfn get_replacement_for_position(position: &str) -> Option<&'static str> {\n    match position {\n        \"beforebegin\" => Some(\"before\"),\n        \"afterbegin\" => Some(\"prepend\"),","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/prefer_modern_dom_apis.rs#L1-L34","documentation":"Diagnostic from the unicorn/prefer-modern-dom-apis lint rule. It fires when a call uses an older DOM API that has a modern, standardized replacement (e.g. `document.execCommand('bold')` vs the `beforeinput`/Selection APIs, `Node.rootNode` vs `Node.getRootNode()`); the message names both the recommended `good_method` and the flagged `bad_method`. It is a lint suggestion, not a runtime error.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/prefer_modern_dom_apis.rs:16 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace the flagged call with the modern API named in the message","Update surrounding code to the modern API's signature (they may differ in arguments/return)","Apply the rule's auto-fix where one exists"],"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-14T05:17:10.506Z"}