An ESLint plugin for enforcing consistent imports across monorepo packages.
npm install eslint-plugin-workspacesAn ESLint plugin for enforcing consistent imports across monorepo packages.
It supports:
- Yarn workspaces
- npm workspaces
- pnpm workspaces
- lerna
- bolt
``shnpm
npm install eslint-plugin-workspaces --save-dev
Configuration
Enable the rules in your ESLint configuration file:
`json
{
"plugins": ["workspaces"],
"rules": {
"workspaces/no-relative-imports": "error",
"workspaces/require-dependency": "warn"
}
}
`Or add the "recommended" preset:
`json
{
"extends": ["plugin:workspaces/recommended"]
}
`$3
Enable the rules in your ESLint configuration file:
`js
import workspaces from "eslint-plugin-workspaces";export default [
{
plugins: { workspaces },
rules: {
"workspaces/no-relative-imports": "error",
"workspaces/require-dependency": "warn",
},
},
// ...
];
`Or add the "recommended" preset:
`js
import workspaces from "eslint-plugin-workspaces";export default [
workspaces.configs["flat/recommended"],
// ...
];
`Rules
ā included in the "recommended" preset
š§ fixable using the
--fix command line option| | | Name | Description |
| --- | --- | ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
| ā | š§ | no-absolute-imports | disallow absolute imports for files that are within the current package |
| | | no-cross-imports | disallow imports of files that are inside another package |
| ā | š§ | no-relative-imports | disallow relative imports of files that are outside of the current package |
| ā | | require-dependency | disallow importing from packages that are not listed as a dependency |
Presets
-
recommended enables rules recommended for all users
- all enables all rules
- flat/recommended enables rules recommended for all users
- flat/all` enables all rules