Socket
Book a DemoInstallSign in
Socket

eslint-plugin-khvala-imports

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

eslint-plugin-khvala-imports

ESLint plugins for imports

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

ESLint Plugin: Import Path Restrictions

This ESLint plugin provides rules to enforce import path restrictions in your codebase. It helps maintain a clean and organized project structure by preventing imports from restricted directories.

Installation

npm install --save-dev @mwkt/eslint-plugin-imports

Usage

Add the plugin to your ESLint configuration:

{
  "plugins": ["imports"],
  "rules": {
    "imports/restrict-import-paths": "error"
  }
}

Rule: restrict-import-paths

This rule enforces restrictions on import paths in your codebase. It can be configured to:

  • Apply only to specific source folders
  • Restrict imports from certain directories

Options

The rule accepts an array of configuration objects, where each object can have the following properties:

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

Example Configuration

{
  "rules": {
    "imports/restrict-import-paths": ["error", {
      "sourceFolders": ["client/lib/components"],
      "restrictedFolders": ["@lib/modules"]
    }]
  }
}

You can also provide multiple configuration objects to apply different restrictions to different source folders:

{
  "rules": {
    "imports/restrict-import-paths": ["error", 
      {
        "sourceFolders": ["client/lib/components"],
        "restrictedFolders": ["@lib/modules"]
      },
      {
        "sourceFolders": ["server/api"],
        "restrictedFolders": ["@lib/client"]
      }
    ]
  }
}

Examples

The rule will report errors for:

// ❌ Importing from a restricted folder
import { something } from '../modules/feature';

// ❌ Requiring from a restricted folder
const something = require('../modules/feature');

// ✅ Importing from allowed folders
import { something } from '../components/feature';

Features

  • Supports both ES6 imports and CommonJS require statements
  • Configurable source and restricted folders
  • Only applies to specified source files
  • Easy to integrate with existing ESLint configurations

Keywords

eslint

FAQs

Package last updated on 14 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