import/newline-after-import
Require an empty line between the last import and the code that follows
fixable
Also called import-x/newline-after-import
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.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"import/newline-after-import" = "error" # or "warn"Every option, set to its default:
bunfig.toml
[lint.rules]
"import/newline-after-import" = ["error", {
count = 1,
exactCount = false,
considerComments = false,
}]Examples#
example.js1 problem
import { readFile } from "node:fs/promises";
iExpected 1 empty line after import statement not followed by another import.mport { join } from "node:path";
const root = join(import.meta.dirname, "..");example.js1 problem
cExpected 1 empty line after require statement not followed by another require.onst { join } = require("node:path");
const root = join(__dirname, "..");example.jsNo problems
import { readFile } from "node:fs/promises";
import { join } from "node:path";
const root = join(import.meta.dirname, "..");example.jsNo problems
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. |
example.jswith
{ "count": 2 }1 problemiExpected 2 empty lines after import statement not followed by another import.mport { join } from "node:path";
const root = join(import.meta.dirname, "..");example.jsNo problems
import { join } from "node:path";
const root = join(import.meta.dirname, "..");example.jswith
{ "exactCount": true }1 problemiExpected 1 empty line after import statement not followed by another import.mport { join } from "node:path";
const root = join(import.meta.dirname, "..");example.jsNo problems
import { join } from "node:path";
// The root of the repository.
const root = join(import.meta.dirname, "..");example.jswith
{ "considerComments": true }1 problemiExpected 1 empty line after import statement not followed by another import.mport { join } from "node:path";
// The root of the repository.
const root = join(import.meta.dirname, "..");