You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(linter): Fix the logic for unicorn/prefer-dom-node-remove to handle literal callees as well as arguments. (#20059)
Two main changes:
- Fix the diagnostic. It was clearly the victim of a copy-paste mistake at some point. Also added a note with a relevant MDN URL.
- Add a bunch of tests from the upstream that didn't get ported by our rulegen tooling. And then fix the rule so it doesn't miss out on violations in a lot of the test cases.
```js
// Prior to this PR, the rule handled these cases:
foo.removeChild(true)
foo.removeChild("")
foo.removeChild(undefined)
// But not these:
(true).removeChild(foo)
("").removeChild(foo)
(undefined).removeChild(foo)
```
See https://github.com/sindresorhus/eslint-plugin-unicorn/blob/609d4870f3731d39bd5b5f184628e2cf06578dba/test/prefer-dom-node-remove.js for the original test generation logic.
AI Disclosure: I used Claude Code to fix up the logic for catching the extra cases.
/// The DOM function [`Node#remove()`](https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove) is preferred over the indirect removal of an object with [`Node#removeChild()`](https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild).
30
+
/// The DOM function [`Node#remove()`](https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove) is preferred
31
+
/// over the indirect removal of an object with [`Node#removeChild()`](https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild).
30
32
///
31
33
/// ### Examples
32
34
///
@@ -45,6 +47,21 @@ declare_oxc_lint!(
45
47
pending
46
48
);
47
49
50
+
/// Returns `true` if the expression is a type that can never be a DOM node
0 commit comments