eslint-plugin-restrict-imports

raw JSON →
0.0.3 verified Sat Apr 25 auth: no javascript maintenance

An ESLint plugin (v0.0.3) for restricting imports from specified paths in specified directories. Useful for enforcing barrel imports or preventing cross-package imports in monorepos. Rules use regex patterns to match import paths and file locations. Extends ESLint's plugin architecture and is compatible with Node >=0.10.0. No active maintenance since 2019, limited documentation, and no TypeScript support.

error Error: Cannot find module 'eslint-plugin-restrict-imports'
cause Plugin is not installed or ESLint cannot resolve it.
fix
Run npm install eslint-plugin-restrict-imports --save-dev and ensure node_modules contains the plugin.
error Configuration for rule 'restrict-imports/restrict-imports' is invalid: Expected an array but got something else
cause Rule configuration is not in the correct array format (e.g., missing severity level).
fix
Ensure the rule value is an array: ["error", {...}].
error ESLint: Rules with multiple sources do not have a deterministic order
cause Plugin is loaded alongside another plugin that defines the same rule.
fix
Remove duplicate rule definitions or ensure only one source defines 'restrict-imports/restrict-imports'.
gotcha Plugin version 0.0.3 is no longer maintained; no updates since 2019. May have unresolved bugs.
fix Consider using alternative plugins like eslint-plugin-import with no-restricted-paths or eslint-plugin-boundaries.
gotcha Rule configuration uses regex strings for both import paths and file locations. Improper escaping can cause unexpected behavior.
fix Test regex patterns thoroughly; use tools like regex101.com to validate.
gotcha Plugin does not support TypeScript imports or path aliases (e.g., tsconfig paths).
fix Use eslint-plugin-import with import/no-restricted-paths or eslint-plugin-boundaries for TypeScript projects.
gotcha The rule name is redundantly named 'restrict-imports/restrict-imports'. This can cause confusion when configuring.
fix Remember the rule ID is 'restrict-imports/restrict-imports', not just 'restrict-imports'.
npm install eslint-plugin-restrict-imports
yarn add eslint-plugin-restrict-imports
pnpm add eslint-plugin-restrict-imports

Configures eslint-plugin-restrict-imports to ban imports from clientA in clientB and direct common imports in client directories.

// .eslintrc
{
  "plugins": ["restrict-imports"],
  "rules": {
    "restrict-imports/restrict-imports": [
      "error",
      {
        "../../clientA(.*)": {
          "locations": ["(.*)/clientB(.*)"],
          "message": "Do not import client A in client B"
        },
        "(.*)/common/(.*)": {
          "locations": ["(.*)/client(.*)"],
          "message": "Use barrelled import '@common'"
        }
      }
    ]
  }
}

// Run ESLint
// npx eslint src/