oxc-project/oxc · error · OxcDiagnostic

Prefer `Node#append()` over `Node#appendChild()` for DOM nod

Error message

Prefer `Node#append()` over `Node#appendChild()` for DOM nodes.

What it means

Diagnostic from the unicorn/prefer-dom-node-append lint rule. It fires when `appendChild()` is called on a DOM node, because the newer `append()` API accepts multiple arguments and DOM strings, while behaving the same for single-node insertion. The rule flags the `appendChild` member-call span. It is a style suggestion for modern DOM code, not a runtime error.

Source

Thrown at crates/oxc_linter/src/rules/unicorn/prefer_dom_node_append.rs:9

use oxc_ast::{AstKind, ast::MemberExpression};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

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

fn prefer_dom_node_append_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Prefer `Node#append()` over `Node#appendChild()` for DOM nodes.")
        .with_help("Replace `Node#appendChild()` with `Node#append()`.")
        .with_label(span)
}

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

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Enforces the use of, for example, `document.body.append(div);` over `document.body.appendChild(div);` for DOM nodes.
    ///
    /// ### Why is this bad?
    ///
    /// There are [some advantages of using `Node#append()`](https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/append), like the ability to append multiple nodes and to append both [`DOMString`](https://developer.mozilla.org/en-US/docs/Web/API/DOMString) and DOM node objects.
    ///
    /// ### Examples
    ///

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Replace `parent.appendChild(child)` with `parent.append(child)`
  2. Use `append()`'s multi-argument/string support when inserting several nodes or text
  3. Apply the rule's auto-fix
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/prefer_dom_node_append.rs:9 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/0e4b1f2f2fb8a72a. Report an issue: GitHub.