# n/no-mixed-requires

> Disallow `require()` calls mixed with other variables in one declaration

A declaration that lists modules and ordinary variables together makes it hard to see what the file depends on. This rule wants the `require()` calls in their own declaration.

`require("x")` and a property of it, such as `require("x").y`, count as a `require()`. Everything else is an ordinary variable, including one without a value.

{/* 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]
"n/no-mixed-requires" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"n/no-mixed-requires" = ["error", {
  grouping = false,
  allowCall = false,
}]
```

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

## Examples

Reported:

{/* bad */}
```js
const fs = require("fs"),
  retries = 3;
```

Not reported:

{/* good */}
```js
const fs = require("fs"),
  join = require("path").join;

const retries = 3;
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `grouping` | `false` | Also report a declaration that mixes kinds of modules: Node.js built-ins, packages, files (`./`, `../`, `/`), and computed names. |
| `allowCall` | `false` | Count a module that's called right away, such as `require("debug")("app")`, as a `require()`. |

You can write `true` instead of `{ "grouping": true }`.

{/* bad {"options": [{"grouping": true}]} */}
```js
const fs = require("fs"),
  express = require("express"),
  routes = require("./routes");
```

{/* good {"options": [{"grouping": true}]} */}
```js
const fs = require("fs"),
  path = require("path");

const express = require("express");

const routes = require("./routes");
```

A name with the `node:` prefix counts as a package, not as a built-in:

{/* bad {"options": [{"grouping": true}]} */}
```js
const fs = require("node:fs"),
  path = require("path");
```

Without `allowCall`, a module that's called counts as an ordinary variable:

{/* bad */}
```js
const express = require("express"),
  debug = require("debug")("app");
```

{/* good {"options": [{"allowCall": true}]} */}
```js
const express = require("express"),
  debug = require("debug")("app");
```
