Socket
Book a DemoInstallSign in
Socket

eslint-plugin-import-paths

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

eslint-plugin-import-paths

ESLint plugin to enforce directory import rules

latest
npmnpm
Version
1.1.0
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

eslint-plugin-import-paths

An ESLint plugin that enforces directory import rules in your project.

Installation

npm install --save-dev eslint-plugin-import-paths

Usage

Add the plugin to your ESLint configuration:

{
  "plugins": ["import-paths"],
  "rules": {
    "import-paths/restrict-import-paths": ["error", {
      "sourceFolders": ["/components/"],
      "restrictedFolders": ["/modules/"]
    }]
  }
}

Rules

restrict-import-paths

This rule prevents files in specified source directories from importing files from restricted directories.

Configuration

The rule accepts an options object with the following properties:

  • sourceFolders (string[]): List of folder paths where the rule should be applied. Default: ["/components/"]
  • restrictedFolders (string[]): List of folder paths that should not be imported from. Default: ["/modules/"]

Examples

Default configuration (components cannot import from modules):

{
  "import-paths/restrict-import-paths": "error"
}

Custom configuration:

{
  "import-paths/restrict-import-paths": ["error", {
    "sourceFolders": ["/components/", "/features/"],
    "restrictedFolders": ["/modules/", "/internal/"]
  }]
}

Valid:

// In /components/MyComponent.tsx
import { something } from './local-file';
import { other } from '../../components/OtherComponent';

// In /features/MyFeature.tsx (with custom config)
import { something } from './local-file';
import { other } from '../../components/OtherComponent';

Invalid:

// In /components/MyComponent.tsx
import { something } from '../../modules/SomeModule';
import { other } from '@/modules/OtherModule';

// In /features/MyFeature.tsx (with custom config)
import { something } from '../../internal/SomeModule';

License

ISC

Keywords

eslint

FAQs

Package last updated on 06 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts