# import/namespace

> Require each property read from an `import * as` namespace to be exported by that file

With `import * as api from "./api"`, reading a name that `./api` doesn't export gives `undefined`, and nothing fails until you call it. Assigning to `api.save` throws, because a namespace object is read-only.

The rule reads the imported file and checks `api.name`, `const { name } = api` and `<api.Name />`. A computed read like `api[key]` can't be checked, so it's reported too unless you allow it.

It reads JavaScript and TypeScript files, including JSX. With an ESLint config it only reads `.js`, `.mjs` and `.cjs` files, unless `settings["import/extensions"]` lists others.

{/* 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]
"import/namespace" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"import/namespace" = ["error", {
  allowComputed = false,
}]
```

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

## Examples

Reported:

{/* file "api.js" */}
```js
export function save(item) {}
export function load(id) {}
```

{/* bad {"count": 4} */}
```js
import * as api from "./api.js";

api.remove("draft");
const { update } = api;
api.save = () => {};

const action = "load";
api[action]("draft");
```

Not reported:

{/* file "api.js" */}
```js
export function save(item) {}
export function load(id) {}
```

{/* good */}
```js
import * as api from "./api.js";

api.save({ id: "draft" });
const { load } = api;
load("draft");
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `allowComputed` | `false` | Allow computed reads such as `api[key]`. They aren't checked. |

{/* file "api.js" */}
```js
export function save(item) {}
export function load(id) {}
```

{/* good {"options": [{"allowComputed": true}]} */}
```js
import * as api from "./api.js";

const action = "load";
api[action]("draft");
```
