Skip to content

unicorn/prefer-dom-node-append Pedantic

🛠️ An auto-fix is available for this rule.

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(), like the ability to append multiple nodes and to append both DOMString and DOM node objects.

Examples

Examples of incorrect code for this rule:

javascript
foo.appendChild(bar);

Examples of correct code for this rule:

javascript
foo.append(bar);

How to use

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny unicorn/prefer-dom-node-append
json
{
  "rules": {
    "unicorn/prefer-dom-node-append": "error"
  }
}

References

Released under the MIT License.