This rule enforces (and autofixes) that import
statements and require
calls — henceforth referred to as just "imports" — appear in the groups described in our guidelines.
Imports appear in the following groups, separated by a blank line:
- "External" imports (ie. NodeJS built-in modules and dependencies specified in "package.json"; these do not start with "." or "..").
- "Internal" imports (ie. local to the projects, starting with "." or "..");
- "Side-effect-only" imports.
Additionally, any import that is preceded by a comment must be prefaced by a blank line for readability.
This rule just enforces the blank lines before and after each group. The ordering between groups, and within each group, is enforced separately, by the sort-imports rule.
See the links in the Further Reading section below for the rationale behind this pattern.
Examples of incorrect code for this rule:
import {g, z} from 'one';
import {a} from 'other';
// Comment describing the next import.
import stuff from 'stuff';
import 'side-effect';
import x from './x';
Examples of correct code for this rule:
import {g, z} from 'one';
import {a} from 'other';
// Comment describing the next import.
import stuff from 'stuff';
import 'side-effect';
import x from './x';