Skip to main content

disallow-import

Disallow import/export sources by configured glob patterns.

Targeted pattern scope

This rule checks module source strings in:

  • import ... from "..."
  • export ... from "..."
  • export * from "..."
  • dynamic import("...")

It matches those source values against glob patterns.

What this rule reports

This rule matches import and export source values against disallow globs, with optional allow exceptions.

Why this rule exists

This rule is a general boundary primitive: it lets you ban path families and optionally carve out explicit exceptions.

❌ Incorrect

import value from "../source";

with options:

{
disallow: ["../**"];
}

✅ Correct

import value from "../source";

with options:

{ disallow: ["../**"], allow: ["../source"] }

Behavior and migration notes

This rule reports only and does not provide an autofix.

Because the default disallow set is empty, this rule does nothing until you configure disallow patterns.

Options

type Options = {
allow?: string[];
disallow?: string[];
};

Additional examples

// config: { disallow: ["../**"], allow: ["../shared/**"] }
import util from "../feature/util";
// ❌ reported

import shared from "../shared/math";
// ✅ allowed by explicit exception

ESLint flat config example

import etcMisc from "eslint-plugin-etc-misc";

export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/disallow-import": ["error", { disallow: ["../**"] }],
},
},
];

When not to use it

Disable this rule if your project does not enforce import path restrictions.

Package documentation

Rule catalog ID: R012

Further reading

Adoption resources

  • Start at warning level in CI, then move to error after cleanup.
  • Use focused codemods/autofix batches per package or directory.