Linter · Rules
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:
[lint.rules]
"no-restricted-exports" = "error" # or "warn"
Every option, set to its default. The ones that are commented out are unset by default.
[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
[lint.rules]
no-restricted-exports = ["error", { restrictedNamedExports = ["then"] }]
Reported:
export function then(callback) {
callback("ready");
}
Not reported:
export function whenReady(callback) {
callback("ready");
}
The rule checks the name that other modules see, not the local one:
function whenReady(callback) {
callback("ready");
}
export { whenReady as then };
Options
| Option | Default | What it does |
|---|---|---|
restrictedNamedExports | [] | Names that can't be exported. |
restrictedNamedExportsPattern | none | A 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: "^_" }:
export const _cache = new Map();
Each key of restrictDefaultExports is false by default:
| Key | What it reports |
|---|---|
direct | export default value |
named | export { value as default } |
defaultFrom | export { default } from "./user.js" |
namedFrom | export { user as default } from "./user.js" |
namespaceFrom | export * as default from "./user.js" |
With { restrictDefaultExports: { direct: true, named: true } }:
export default class User {}
Any form you didn't turn on is still allowed:
export { default } from "./user.js";