import/exports-last

Require all exports to come after every other statement in the file

Also called import-x/exports-last

When exports are spread through a file, you have to read all of it to learn what it offers. With every export at the bottom, the last lines of the file are its public interface.

An export is reported if any statement that isn't an export comes after it. This applies to every kind: export const, export function, export default, export { } and export * from.

Configure#

Off by default. To turn it on:

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

Examples#

example.js1 problem
export const retries = 3;

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

export { wait };
example.jsNo problems
const retries = 3;

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

export { retries, wait };
example.jsNo problems
const cache = new Map();

export const retries = 3;
export function clear() {
  cache.clear();
}
export default cache;