import/group-exports

Require all named exports to be in a single export declaration

Also called import-x/group-exports

When export is written on many declarations, you have to scan the whole file to learn what it exports. One export { } list, or one assignment to module.exports, shows it in one place.

As soon as there are two exports, each of them is reported. Values, types (export type) and re-exports from each module (export { } from) are counted separately. A default export doesn't count.

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"import/group-exports" = "error" # or "warn"

Examples#

example.js2 problems
export const retries = 3;

export function wait(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}
example.js2 problems
export { parse } from "./json.js";
export { stringify } from "./json.js";
example.js2 problems
exports.retries = 3;
module.exports.wait = ms => new Promise(resolve => setTimeout(resolve, ms));
example.jsNo problems
const retries = 3;

function wait(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

export { retries, wait };
export default wait;
example.jsNo problems
export { parse, stringify } from "./json.js";
export { encode } from "./base64.js";
example.jsNo problems
const retries = 3;
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));

module.exports = { retries, wait };
example.tsNo problems
interface Options {
  retries: number;
}
const defaults: Options = { retries: 3 };

export { defaults };
export type { Options };