Skip to content
← Back to rules

unicorn/require-module-attributes 风格

An auto-fix is available for this rule.

它做了什么

此规则强制在 import/export 语句和 import() 表达式中使用非空的属性列表。

为什么这是不好的?

导入属性旨在提供有关如何加载模块的元数据(例如 with { type: "json" })。一个空的属性对象不提供任何信息,应当被移除。

示例

此规则的错误代码示例:

js
import foo from "foo" with {};

export { foo } from "foo" with {};

const foo = await import("foo", {});

const foo = await import("foo", { with: {} });

此规则的正确代码示例:

js
import foo from "foo";

export { foo } from "foo";

const foo = await import("foo");

const foo = await import("foo");

如何使用

要通过配置文件或 CLI 启用此规则,可以使用:

json
{
  "rules": {
    "unicorn/require-module-attributes": "error"
  }
}
bash
oxlint --deny unicorn/require-module-attributes

参考资料