Skip to content
← Back to rules

import/exports-last 风格

它的作用

此规则强制要求所有导出声明位于文件末尾。
该规则会报告任何在非导出语句之前出现的导出声明。

为什么这是个问题?

将导出分散在文件各处会导致代码可读性差,
并增加快速定位导出内容的成本。

示例

此规则的 错误 示例:

js
const bool = true;
export const foo = "bar";
const str = "foo";

此规则的 正确 示例:

js
const arr = ["bar"];
export const bool = true;
export const str = "foo";
export function func() {
  console.log("Hello World");
}

如何使用

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

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

参考资料