eslint-plugin-import-path

raw JSON →
0.0.2 verified Sat Apr 25 auth: no javascript

A tiny ESLint plugin (v0.0.2) for checking import/export paths against forbidden patterns and depth limits. It allows defining regex-based or substring-based blacklists and a maximum parent directory depth. Unlike the more comprehensive eslint-plugin-import, this plugin focuses solely on simple path validation without full module resolution. It is stable enough for development use, but the version 0.0.2 indicates it is still in early stages with no release cadence. Key differentiators: lightweight, no external dependencies beyond ESLint, and supports both regex and substring matching with custom error messages.

error ESLint couldn't find the plugin "eslint-plugin-import-path".
cause The plugin is not installed or not listed in the devDependencies.
fix
Run npm install eslint-plugin-import-path --save-dev
error Configuration for rule "import-path/forbidden" is invalid: severity should be one of off, warn, error.
cause The rule severity is set to an invalid value (e.g., 'warning' instead of 'warn').
fix
Use one of: 'off', 'warn', or 'error'.
gotcha The 'forbidden' rule uses regex strings; ensure you escape backslashes and special characters appropriately in JSON.
fix Use double escaping in JSON strings, e.g., 'match': '\\.' for a literal '.'
gotcha The 'forbidden' rule with 'contains' property does simple substring matching, not regex; ensure you use 'match' for regex patterns.
fix Use 'match' for regex, 'contains' for plain substring.
npm install eslint-plugin-import-path
yarn add eslint-plugin-import-path
pnpm add eslint-plugin-import-path

Installs the plugin and configures two rules: forbidding paths ending in '/index' and limiting parent directory depth to 2.

// Install the plugin
npm install eslint-plugin-import-path --save-dev

// In your .eslintrc (JSON or JS config):
{
  "plugins": ["import-path"],
  "rules": {
    "import-path/forbidden": ["warn", ["/index$"]],
    "import-path/parent-depth": ["warn", 2]
  }
}

// Now ESLint will warn on imports like:
import Foo from 'somewhere/index';  // warns: path matches /index$
import Bar from '../../../../../deep'; // warns: depth > 2