Skip to main content

Require Import Order

Require 6-group import ordering: regular Node built-ins, regular third-party, regular local, then type Node built-ins, type third-party, type local — each group separated by a blank line and sorted alphabetically within.

Summary

The require-import-order rule enforces a strict 6-group ordering:

  1. Regular Node built-ins
  2. Regular third-party
  3. Regular local
  4. Type Node built-ins
  5. Type third-party
  6. Type local

Groups must be separated by blank lines, and imports within the same group must be in alphabetical order. Import specifiers within a single import statement must also be alphabetical.

Why Use This Rule?

  1. Consistent import ordering makes it easy to locate a specific import at a glance.
  2. Blank lines between groups visually separate concerns — platform, dependencies, and project code.
  3. Alphabetical ordering within groups eliminates merge conflicts from arbitrary insertion order.

Examples

Configuration

Options

warning

ignoreFiles is an escape hatch for files where this rule genuinely does not apply. It is not intended for routine use.

OptionTypeDefaultDescription
ignoreFilesstring[][]File patterns to skip.

Autofix

Autofix is not available for this rule. Flagged code must be updated manually.

Troubleshooting

  • Warning fires on a type import before a local import — Type imports always come after all regular imports. Move import type statements to the end of the import block.
  • Warning says specifiers are not alphabetical — Named specifiers inside { A, B, C } must be sorted alphabetically. Reorder them to match.
  • Bare Node built-in without node: prefix is flagged — The rule recognizes bare built-in module names (e.g., fs, path) and treats them the same as node:fs. If it is flagged, the ordering issue is with the group, not the prefix.