Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

Latest commit

 

History

History
48 lines (31 loc) · 1.61 KB

File metadata and controls

48 lines (31 loc) · 1.61 KB

Group import statements and require calls (group-imports)

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.

Rule Details

Imports appear in the following groups, separated by a blank line:

  1. "External" imports (ie. NodeJS built-in modules and dependencies specified in "package.json"; these do not start with "." or "..").
  2. "Internal" imports (ie. local to the projects, starting with "." or "..");
  3. "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

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';

Further Reading