eslint-plugin-monorepo
eslint-plugin-monorepo copied to clipboard
Suggestion: Add Rule to Disallow Imports Between Certain Packages
Our repo is structured into yarn workspaces like this:
- applications/app1
- applications/app2
- common/c1
- common/c2
The desired rule is that applications might import from packages common/c1 and common/c2, but never from another application. In other words, in app1 there must never be an import from app2.
Currently we use depencency-cruiser for such advanced checks. Sounds like a good use case for this plugin though.
Was looking for the exact same feature :) Is this somehow possible using this package or any other lint plugin?
assume your application package has an @application prefix then, using standard eslint rule
"no-restricted-imports": ["error",
{
name: '@applications/*',
message: 'Please don't import from another application. Extract common parts into separate package.'
}
]
And you either can put this into your root .eslintrc.js or create a dedicated in a sub-package folder.
what about cases of importing a backend package from a frontend package?
"no-restricted-imports": ["error",
{
restrictImportOf: '@backend/*',
restrictOnlyFrom: '@frontend/*',
message: 'Please don't import packages from backend to frontend code.'
},
{
restrictImportOf: '@frontend/*',
restrictOnlyFrom: '@backend/*',
message: 'Please don't import packages from frontend to backend code.'
}
]