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:
import { something } from './local-file';
import { other } from '../../components/OtherComponent';
import { something } from './local-file';
import { other } from '../../components/OtherComponent';
Invalid:
import { something } from '../../modules/SomeModule';
import { other } from '@/modules/OtherModule';
import { something } from '../../internal/SomeModule';
License
ISC