no-restricted-exports

Disallow the export names you list, or default exports

Some export names cause trouble. A module that exports a function named then looks like a promise, so await import("./module.js") calls that function instead of giving you the module. Your project may also want named exports only, so everything keeps the same name wherever it's imported.

The rule does nothing until you give it options.

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"no-restricted-exports" = "error" # or "warn"

Every option, set to its default. The ones that are commented out are unset by default.

bunfig.toml
[lint.rules]
"no-restricted-exports" = ["error", {
  restrictedNamedExports = [], # list of strings
  # restrictedNamedExportsPattern = <string>,
  restrictDefaultExports = {
    # direct = <true or false>,
    # named = <true or false>,
    # defaultFrom = <true or false>,
    # namedFrom = <true or false>,
    # namespaceFrom = <true or false>,
  },
}]

Examples#

bunfig.toml
[lint.rules]
no-restricted-exports = ["error", { restrictedNamedExports = ["then"] }]
example.jswith { "restrictedNamedExports": ["then"] }1 problem
export function then(callback) {
  callback("ready");
}
example.jswith { "restrictedNamedExports": ["then"] }No problems
export function whenReady(callback) {
  callback("ready");
}

The rule checks the name that other modules see, not the local one:

example.jswith { "restrictedNamedExports": ["then"] }1 problem
function whenReady(callback) {
  callback("ready");
}

export { whenReady as then };

Options#

OptionDefaultWhat it does
restrictedNamedExports[]Names that can't be exported.
restrictedNamedExportsPatternnoneA regular expression. Every exported name that matches it is reported, except default.
restrictDefaultExports{}Which ways of writing a default export are reported. See the second table.

With { restrictedNamedExportsPattern: "^_" }:

example.jswith { "restrictedNamedExportsPattern": "^_" }1 problem
export const _cache = new Map();

Each key of restrictDefaultExports is false by default:

KeyWhat it reports
directexport default value
namedexport { value as default }
defaultFromexport { default } from "./user.js"
namedFromexport { user as default } from "./user.js"
namespaceFromexport * as default from "./user.js"

With { restrictDefaultExports: { direct: true, named: true } }:

example.jswith { "restrictDefaultExports": { "direct": true, "named": true } }1 problem
export default class User {}

Any form you didn't turn on is still allowed:

example.jswith { "restrictDefaultExports": { "direct": true, "named": true } }No problems
export { default } from "./user.js";