Skip to content
← Back to rules

unicorn/require-module-attributes Style

💡 A suggestion 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");

如何使用

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

json
{
  "rules": {
    "unicorn/require-module-attributes": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "unicorn/require-module-attributes": "error",
  },
});
bash
oxlint --deny unicorn/require-module-attributes

版本

此规则在 v1.35.0 中新增。

参考资料