Skip to content
← Back to rules

unicorn/prefer-dom-node-remove Pedantic

🚧 An auto-fix is planned for this rule, but not implemented at this time.

作用

更倾向于使用 child.remove(),而不是 parentNode.removeChild(child)

为什么这不好?

优先使用 DOM 函数 Node#remove(), 而不是通过 Node#removeChild() 间接移除对象。

示例

以下是此规则的错误代码示例:

javascript
parentNode.removeChild(childNode);

以下是此规则的正确代码示例:

javascript
childNode.remove();

如何使用

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

json
{
  "rules": {
    "unicorn/prefer-dom-node-remove": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "unicorn/prefer-dom-node-remove": "error",
  },
});
bash
oxlint --deny unicorn/prefer-dom-node-remove

版本

此规则是在 v0.0.18 中添加的。

参考资料