# import/no-unassigned-import

> Disallow imports that bind no name

`import "./setup.js"` runs a module only for its side effects. Nothing in the file shows what the module changes, and the order of these imports matters even though nothing says so. With this rule on, every import needs to bring in a name you can follow.

A `require()` call that's a statement by itself is reported too, and so is an import with empty braces.

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

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

```toml bunfig.toml
[lint.rules]
"import/no-unassigned-import" = ["error", {
  allow = [], # list of strings
  # devDependencies = <true, false or list>,
  # optionalDependencies = <true, false or list>,
  # peerDependencies = <true, false or list>,
}]
```

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

## Examples

Reported:

{/* bad {"count": 3} */}
```js
import "./register-globals.js";
import {} from "lodash";
require("./patch-console.js");
```

Not reported:

{/* good */}
```js
import { registerGlobals } from "./register-globals.js";
const patchConsole = require("./patch-console.js");

registerGlobals();
patchConsole();
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `allow` | `[]` | Globs for modules you can import for their side effects. |

A package name is matched exactly as you wrote it. A relative path is made absolute first, so a glob for files either starts with `**/` or is relative to the directory you run `bun lint` in.

`devDependencies`, `optionalDependencies` and `peerDependencies` are accepted but have no effect.

```toml bunfig.toml
[lint.rules]
"import/no-unassigned-import" = ["error", {
  allow = ["**/*.css", "reflect-metadata"],
}]
```

With this configuration, these are allowed:

{/* good {"root": true, "options": [{"allow": ["**\/*.css", "reflect-metadata"]}]} */}
```js
import "./app.css";
import "reflect-metadata";
```

And this is still reported:

{/* bad {"root": true, "options": [{"allow": ["**\/*.css", "reflect-metadata"]}]} */}
```js
import "./register-globals.js";
```

## When not to use it

Stylesheets, polyfills and test setup files are meant to be imported this way. If you'd end up listing most of your side-effect imports in `allow`, leave the rule off.
