ESLint plugin to enforce custom module dependency rules in TypeScript projects. Current stable version is 1.3.33, released under MIT license. It uses tsconfig paths for alias resolution and supports glob patterns, forward matching, and per-rule allow-lists for import sources. Unlike generic import lint rules, it allows granular control over which modules can import from which paths, including member-level restrictions (e.g., disallowing `Suspense` from `react` except in a specific file). It also offers options like `resolveRelativeImport` to convert relative imports to absolute paths for linting, and `excludeTypeImportChecks` to skip type-only imports. The plugin is actively maintained with regular dependency updates but no major feature changes recently.
npm install eslint-plugin-strict-dependenciesVerified import paths — ran on the pinned version, not inferred.
This shows how to configure the plugin to restrict imports: 'src/components/ui' can only be imported from 'src/components/page', and 'next/router' can only be imported from 'src/libs/router.ts'.
Ensure tsconfig.json exists and has the necessary paths compilerOptions (if using alias resolution).
Use the 'pathIndexMap' option to specify which index to use for each key.
Set the 'resolveRelativeImport' option to true in the rule options to convert relative imports to absolute paths for linting.
Always test your patterns and prefer explicit glob patterns (e.g., 'src/modules/**') to avoid ambiguity.
Explicitly set 'allowSameModule' to the desired value to avoid breaking changes in future releases.
Run 'npm install eslint-plugin-strict-dependencies --save-dev' or ensure it is in your package.json.
Run 'npm install typescript --save-dev' to add TypeScript as a dev dependency.
Create a tsconfig.json file in your project root, even if minimal, e.g., { "compilerOptions": {} }.Install and configure @typescript-eslint/parser in your ESLint config: 'parser: "@typescript-eslint/parser"'.