import/exports-last Style
作用
此规则强制要求所有导出都声明在文件底部。 此规则会报告任何出现在非导出语句之前的导出声明。
为什么这不好?
导出分散在文件各处会导致代码可读性变差, 并增加快速定位导出的成本
示例
此规则的错误代码示例:
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");
}如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["import"],
"rules": {
"import/exports-last": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["import"],
rules: {
"import/exports-last": "error",
},
});bash
oxlint --deny import/exports-last --import-plugin版本
此规则是在 v0.15.14 中添加的。
