eslint-plugin-workspaces
Version:
An ESLint plugin for enforcing consistent imports across monorepo packages.
98 lines (71 loc) ⢠3.4 kB
Markdown
An ESLint plugin for enforcing consistent imports across monorepo packages.
It supports:
- [Yarn workspaces](https://classic.yarnpkg.com/en/docs/workspaces)
- [npm workspaces](https://docs.npmjs.com/cli/v7/using-npm/workspaces)
- [pnpm workspaces](https://pnpm.io/workspaces)
- [lerna](https://github.com/lerna/lerna)
- [bolt](https://github.com/boltpkg/bolt)
```sh
npm install eslint-plugin-workspaces --save-dev
yarn add eslint-plugin-workspaces --dev
```
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"]
}
```
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"],
// ...
];
```
ā included in the "recommended" preset
š§ fixable using the `--fix` command line option
| | | Name | Description |
| --- | --- | ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
| ā | š§ | [no-absolute-imports](https://github.com/joshuajaco/eslint-plugin-workspaces/blob/main/docs/rules/no-absolute-imports.md) | disallow absolute imports for files that are within the current package |
| | | [no-cross-imports](https://github.com/joshuajaco/eslint-plugin-workspaces/blob/main/docs/rules/no-cross-imports.md) | disallow imports of files that are inside another package |
| ā | š§ | [no-relative-imports](https://github.com/joshuajaco/eslint-plugin-workspaces/blob/main/docs/rules/no-relative-imports.md) | disallow relative imports of files that are outside of the current package |
| ā | | [require-dependency](https://github.com/joshuajaco/eslint-plugin-workspaces/blob/main/docs/rules/require-dependency.md) | disallow importing from packages that are not listed as a dependency |
- `recommended` enables rules recommended for all users
- `all` enables all rules
- `flat/recommended` enables rules recommended for all users
- `flat/all` enables all rules
[](https://github.com/joshuajaco/eslint-plugin-workspaces/blob/main/LICENSE)