Skip to content
NewBun 1.4.5 is out. Release notes
AphrodyBun

Linter · Rules

unicorn/prefer-export-from

Require export ... from to re-export instead of an import and a separate export

An import followed by an export of the same name takes two statements, often far apart, to say one thing. export { parse } from "./parser.js" says it in one place and doesn't add a name to the file's scope.

Configure

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"unicorn/prefer-export-from" = "error" # or "warn"

Every option, set to its default:

bunfig.toml
[lint.rules]
"unicorn/prefer-export-from" = ["error", {
  checkUsedVariables = true,
}]

Examples

Reported:

import { parse } from "./parser.js";

export { parse };
import Button from "./button.js";
import * as icons from "./icons.js";

export default Button;
export { icons };

Not reported:

export { parse } from "./parser.js";
export { default } from "./button.js";
export * as icons from "./icons.js";

Options

OptionDefaultWhat it does
checkUsedVariablestrueAlso report an import that the file uses for something other than exporting it.

By default, this is reported even though the file needs the import for parse(""):

import { parse } from "./parser.js";

export { parse };
export const empty = parse("");

To fix it, keep the import and re-export from the module as well:

import { parse } from "./parser.js";

export { parse } from "./parser.js";
export const empty = parse("");

With false, the rule skips an import statement as soon as the file uses one of its names:

import { parse } from "./parser.js";

export { parse };
export const empty = parse("");