Skip to content

unicorn/prefer-dom-node-remove Pedantic

What it does

Prefers the use of child.remove() over parentNode.removeChild(child).

Why is this bad?

The DOM function Node#remove() is preferred over the indirect removal of an object with Node#removeChild().

Examples

Examples of incorrect code for this rule:

javascript
parentNode.removeChild(childNode);

Examples of correct code for this rule:

javascript
childNode.remove();

How to use

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

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

References

Released under the MIT License.