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.