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.
Common errors
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'.
Warnings
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'.
Install
npm install eslint-plugin-restrict-imports yarn add eslint-plugin-restrict-imports pnpm add eslint-plugin-restrict-imports Imports
- plugin wrong
import restrictImports from 'eslint-plugin-restrict-imports'correctmodule.exports = { plugins: ['restrict-imports'] } - rule restrict-imports/restrict-imports wrong
// Direct import for testing is not supported const rule = require('eslint-plugin-restrict-imports/rules/restrict-imports')correct// In .eslintrc "rules": { "restrict-imports/restrict-imports": ["error", {...}] } - config wrong
// Incorrect: using require for config const config = require('eslint-plugin-restrict-imports/config')correct// .eslintrc configuration object { "plugins": ["restrict-imports"], "rules": { "restrict-imports/restrict-imports": ["error", {...}] } }
Quickstart
// .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/