eslint-plugin-strict-dependencies
ESLint plugin to define custom module dependency rules.
NOTE: eslint-plugin-strict-dependencies
uses tsconfig, tsconfig.json must be present.
Installation
npm install eslint-plugin-strict-dependencies --save-dev
Supported Rules
- strict-dependencies
- module:
string
(Glob or Forward matching string)
- targetMembers:
string[]
- Target member name
- e.x.
["Suspense"]
in import { Suspense } from 'react'
- allowReferenceFrom:
string[]
(Glob or Forward matching string)
- Paths of files where target module imports are allowed.
- allowSameModule:
boolean
- Whether it can be imported by other files in the same directory
- excludeTypeImportChecks:
boolean
- Whether to exclude type import checks
- e.x.
import type { Suspense } from 'react'
Options
Usage
.eslintrc:
"plugins": [
"strict-dependencies",
],
"rules": {
"strict-dependencies/strict-dependencies": [
"error",
[
{
"module": "src/components/page",
"allowReferenceFrom": ["src/pages"],
"allowSameModule": false
},
{
"module": "src/components/ui",
"allowReferenceFrom": ["src/components/page"],
"allowSameModule": true,
"excludeTypeImportChecks": true
},
{
"module": "next/router",
"allowReferenceFrom": ["src/libs/router.ts"],
"allowSameModule": false
},
{
"module": "react",
"targetMembers": ["Suspense"],
"allowReferenceFrom": ["src/libs/react.ts"],
"allowSameModule": false
},
],
]
}
License
MIT