# import/max-dependencies

> Enforce a maximum number of modules that a file can import

A file that imports from many modules usually does too many things, and a change in any of those modules can break it. This rule reports a file that depends on more than `max` modules, 10 by default.

Each module counts once, no matter how many statements import from it. `import`, `export ... from`, `import()` and `require()` all count.

{/* 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/max-dependencies" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"import/max-dependencies" = ["error", {
  max = 10,
  ignoreTypeImports = false,
}]
```

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

## Examples

Reported:

{/* bad {"options": [{"max": 2}]} */}
```js
import { readFile } from "node:fs/promises";
export { parse } from "./parser.js";

const { render } = await import("./render.js");
```

Not reported:

{/* good {"options": [{"max": 2}]} */}
```js
import { readFile } from "node:fs/promises";
import { writeFile } from "node:fs/promises";
import { join, resolve } from "node:path";
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `max` | `10` | The number of modules a file can depend on. |
| `ignoreTypeImports` | `false` | Don't count `import type` statements. |

If you pass options, always include `max`. The default of 10 only applies when there are no options at all. With `{ "ignoreTypeImports": true }` alone, nothing is reported.

{/* bad {"options": [{"max": 1}]} */}
```ts
import { parse } from "./parser";
import type { Token } from "./tokens";
```

{/* good {"options": [{"max": 1, "ignoreTypeImports": true}]} */}
```ts
import { parse } from "./parser";
import type { Token } from "./tokens";
```
