# 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.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml 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.

```toml 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>,
  },
}]
```

{/* End of the generated section. */}

## Examples

```toml bunfig.toml
[lint.rules]
no-restricted-exports = ["error", { restrictedNamedExports = ["then"] }]
```

Reported:

{/* bad {"options": [{"restrictedNamedExports": ["then"]}]} */}
```js
export function then(callback) {
  callback("ready");
}
```

Not reported:

{/* good {"options": [{"restrictedNamedExports": ["then"]}]} */}
```js
export function whenReady(callback) {
  callback("ready");
}
```

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

{/* bad {"options": [{"restrictedNamedExports": ["then"]}]} */}
```js
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: "^_" }`:

{/* bad {"options": [{"restrictedNamedExportsPattern": "^_"}]} */}
```js
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 } }`:

{/* bad {"options": [{"restrictDefaultExports": {"direct": true, "named": true}}]} */}
```js
export default class User {}
```

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

{/* good {"options": [{"restrictDefaultExports": {"direct": true, "named": true}}]} */}
```js
export { default } from "./user.js";
```
