close

prefer-dom-node-append

Unreleased

Configuration

PresetConfigured Value
✅ unicornPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/prefer-dom-node-append': 'error',
    },
  },
]);

Rule Details

Prefer Element#append() over Node#appendChild().

An automatic fix is offered only for expression statements. Other uses are reported without a fix because appendChild returns the appended child, whereas append returns undefined. Computed names and optional calls are excluded. Arguments that are statically impossible DOM nodes, including null, void expressions, and equivalent wrapped or sequence expressions, are ignored; a locally shadowed identifier named undefined is not mistaken for the global value.

Examples of incorrect code:

element.appendChild(child);

Examples of correct code:

element.append(child);

Options

This rule has no options. It is enabled at error severity in unicornPlugin.configs.recommended.

Original Documentation