Skip to content
← Back to rules

unicorn/require-module-specifiers Suspicious

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

作用 ​

强制在 import 和 export 语句中使用非空的说明符列表。

为什么这不好? ​

空的 import/export 说明符没有任何价值,而且可能会令人困惑。 如果你只是想为了副作用而导入一个模块,请改用 import 'module'。

示例 ​

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

js
import {} from "foo";
import foo from "foo";
export {} from "foo";
export {};

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

js
import "foo";
import foo from "foo";

如何使用 ​

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

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

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

版本 ​

此规则在 v1.20.0 中加入。

参考资料 ​