# import/newline-after-import

> Require an empty line between the last import and the code that follows

An empty line after the imports shows where the dependency list ends and the file's code begins.

The rule checks the last `import` in each run of imports, and does the same for top-level `require()` calls. A `require()` inside a function or a block isn't checked.

`--fix` adds the missing empty lines.

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

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"import/newline-after-import" = ["error", {
  count = 1,
  exactCount = false,
  considerComments = false,
}]
```

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

## Examples

Reported:

{/* bad */}
```js
import { readFile } from "node:fs/promises";
import { join } from "node:path";
const root = join(import.meta.dirname, "..");
```

{/* bad */}
```js
const { join } = require("node:path");
const root = join(__dirname, "..");
```

Not reported:

{/* good */}
```js
import { readFile } from "node:fs/promises";
import { join } from "node:path";

const root = join(import.meta.dirname, "..");
```

{/* good */}
```js
const { join } = require("node:path");

const root = join(__dirname, "..");

function loadPlugin(name) {
  const plugin = require("./plugins.js");
  return plugin[name];
}
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `count` | `1` | The minimum number of empty lines. |
| `exactCount` | `false` | Also report more than `count` empty lines. `--fix` doesn't remove them. |
| `considerComments` | `false` | Require the empty lines before a comment that follows the imports. By default a comment can come right after them, and only the distance to the next statement counts. |

{/* bad {"options": [{"count": 2}]} */}
```js
import { join } from "node:path";

const root = join(import.meta.dirname, "..");
```

{/* good */}
```js
import { join } from "node:path";



const root = join(import.meta.dirname, "..");
```

{/* bad {"options": [{"exactCount": true}]} */}
```js
import { join } from "node:path";



const root = join(import.meta.dirname, "..");
```

{/* good */}
```js
import { join } from "node:path";
// The root of the repository.

const root = join(import.meta.dirname, "..");
```

{/* bad {"options": [{"considerComments": true}]} */}
```js
import { join } from "node:path";
// The root of the repository.

const root = join(import.meta.dirname, "..");
```
