Skip to content
← Back to rules

import/group-exports 风格

它的作用

当命名导出未在单个导出声明中分组时,或当一个文件中存在多个对 CommonJS module.exports 或 exports 对象的赋值时,会发出警告。

为什么这是不好的?

导出声明或 module.exports 赋值可以在代码中的任意位置出现。通过要求使用单一的导出声明,可以确保所有导出集中在一个位置,从而更容易查看模块提供了哪些导出。

示例

此规则的 错误 代码示例:

js
export const first = true;
export const second = true;

此规则的 正确 代码示例:

js
const first = true;
const second = true;
export { first, second };

如何使用

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

json
{
  "plugins": ["import"],
  "rules": {
    "import/group-exports": "error"
  }
}
bash
oxlint --deny import/group-exports --import-plugin

参考资料