import/newline-after-import Style
What it does
Enforces having one or more empty lines after the last top-level import statement or require call.
Why is this bad?
Without a blank line, import/require declarations blend into the following logic, which hurts readability and makes changes harder to scan. A blank line clearly separates dependencies from implementation.
Examples
Examples of incorrect code for this rule:
import * as foo from "foo";
const FOO = "BAR";import * as foo from "foo";
const FOO = "BAR";
import { bar } from "bar-lib";const FOO = require("./foo");
const BAZ = 1;
const BAR = require("./bar");Examples of correct code for this rule:
import defaultExport from "./foo";
const FOO = "BAR";import defaultExport from "./foo";
import { bar } from "bar-lib";
const FOO = "BAR";const FOO = require("./foo");
const BAR = require("./bar");
const BAZ = 1;With count set to 2 this will be considered valid:
import defaultExport from "./foo";
const FOO = "BAR";import defaultExport from "./foo";
const FOO = "BAR";With count set to 2 these will be considered invalid:
import defaultExport from "./foo";
const FOO = "BAR";import defaultExport from "./foo";
const FOO = "BAR";With count set to 2 and exactCount set to true this will be considered valid:
import defaultExport from "./foo";
const FOO = "BAR";With count set to 2 and exactCount set to true these will be considered invalid:
import defaultExport from "./foo";
const FOO = "BAR";import defaultExport from "./foo";
const FOO = "BAR";import defaultExport from "./foo";
const FOO = "BAR";import defaultExport from "./foo";
const FOO = "BAR";With considerComments set to false this will be considered valid:
import defaultExport from "./foo";
// some comment here.
const FOO = "BAR";With considerComments set to true this will be considered valid:
import defaultExport from "./foo";
// some comment here.
const FOO = "BAR";With considerComments set to true this will be considered invalid:
import defaultExport from "./foo";
// some comment here.
const FOO = "BAR";Example options usage
{
"rules": {
"import/newline-after-import": ["error", { "count": 1 }]
}
}Configuration
This rule accepts a configuration object with the following properties:
considerComments
type: boolean
default: false
count
type: integer
default: 1
exactCount
type: boolean
default: false
How to use
To enable this rule using the config file or in the CLI, you can use:
{
"plugins": ["import"],
"rules": {
"import/newline-after-import": "error"
}
}import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["import"],
rules: {
"import/newline-after-import": "error",
},
});oxlint --deny import/newline-after-import --import-pluginVersion
This rule was added in vnext.
