This rule raises an issue when legacy DOM manipulation methods like replaceChild(), insertBefore(),
insertAdjacentText(), or insertAdjacentElement() are used instead of their modern equivalents.
Legacy DOM manipulation methods like replaceChild() and insertBefore() require more verbose code and often need you to
traverse to parent nodes unnecessarily.
For example, parentNode.replaceChild(newNode, oldNode) requires you to access the parent node and remember the correct parameter
order. The modern oldNode.replaceWith(newNode) is more intuitive - you call the method directly on the element you want to replace.
Similarly, insertAdjacentText() and insertAdjacentElement() use position strings like 'beforebegin' or 'afterend' that
are harder to remember and less readable than the descriptive method names like before(), after(), append(),
and prepend().
The modern methods also offer additional benefits:
Using legacy DOM methods makes code harder to read and maintain. The verbose syntax and required parent node traversal increase the chance of errors and make the code less intuitive for other developers.
Replace replaceChild() with replaceWith() called directly on the element to be replaced.
parentNode.replaceChild(newElement, oldElement); // Noncompliant
oldElement.replaceWith(newElement);