import/group-exports Style
它的作用
当具名导出没有在单个 export 声明中分组时,或者当对 CommonJS 的 module.exports 或 exports 对象有多个赋值并存在于同一个文件中时,会进行报告。
为什么这不好?
export 声明或 module.exports 赋值可以出现在代码中的任何位置。 通过要求使用单个 export 声明,所有导出都将保持在同一个位置, 这样更容易看出一个模块提供了哪些导出。
示例
以下是此规则的错误代码示例:
js
export const first = true;
export const second = true;以下是此规则的正确代码示例:
js
const first = true;
const second = true;
export { first, second };如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["import"],
"rules": {
"import/group-exports": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["import"],
rules: {
"import/group-exports": "error",
},
});bash
oxlint --deny import/group-exports --import-plugin版本
此规则于 v0.16.6 中新增。
