oxc-project/oxc · error · OxcDiagnostic

Prefer using ` ` over ` `.

Error message

Prefer using `{good_method}` over `{bad_method}`.

What it means

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.

Solutions

  1. Replace the flagged call with the modern API named in the message
  2. Update surrounding code to the modern API's signature (they may differ in arguments/return)
  3. Apply the rule's auto-fix where one exists
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/prefer_modern_dom_apis.rs:16 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/11b1285f0ab101f4. Report an issue: GitHub.

Appendix: source

Thrown at crates/oxc_linter/src/rules/unicorn/prefer_modern_dom_apis.rs:16

use oxc_ast::{
    AstKind,
    ast::{Argument, Expression},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};

use crate::{AstNode, ast_util::is_method_call, context::LintContext, rule::Rule};

fn prefer_modern_dom_apis_diagnostic(
    good_method: &str,
    bad_method: &str,
    span: Span,
) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("Prefer using `{good_method}` over `{bad_method}`."))
        .with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct PreferModernDomApis;

fn get_replacement_for_disallowed_method(method: &str) -> Option<&'static str> {
    match method {
        "replaceChild" => Some("replaceWith"),
        "insertBefore" => Some("before"),
        _ => None,
    }
}

fn get_replacement_for_position(position: &str) -> Option<&'static str> {
    match position {
        "beforebegin" => Some("before"),
        "afterbegin" => Some("prepend"),

View on GitHub (pinned to e1e7af627c)