Skip to content
← Back to rules

unicorn/prefer-node-protocol Restriction

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

作用

导入 Node.js 内置模块时,优先使用 node:protocol

为什么这不好?

应使用 node: 协议导入 Node.js 内置模块,以避免与本地模块产生歧义。

示例

此规则的错误代码示例:

javascript
import fs from "fs";

此规则的正确代码示例:

javascript
import fs from "node:fs";

如何使用

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

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

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

版本

此规则于 v0.0.19 中添加。

参考资料