Skip to content

Commit 7458192

Browse files
authored
Merge pull request #29 from joshuajaco/deprecate-scopes
Deprecate scopes
2 parents 85a78aa + 39497f6 commit 7458192

File tree

3 files changed

+126
-1
lines changed

3 files changed

+126
-1
lines changed

docs/deprecating-scopes.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Deprecating scopes
2+
3+
The [`scopes`](./rules/no-cross-imports.md#scopes-deprecated) option of the [`workspaces/no-cross-imports`](./rules/no-cross-imports.md) rule has been deprecated and will be removed in the next major version.
4+
It was made with a specific use case in mind, but it turned out to be too inflexible and confusing.
5+
Since there are better ways to achieve the same result, the option will be removed.
6+
7+
## Migration
8+
9+
There are two ways to migrate from `scopes` using basic ESLint configuration:
10+
11+
### Using `overrides` (Recommended)
12+
13+
The [`overrides`](https://eslint.org/docs/user-guide/configuring/configuration-files#how-do-overrides-work) key of the ESLint configuration allows you to apply rules differently to a specific set of files.
14+
15+
#### Example
16+
17+
Assuming the following project structure:
18+
19+
```
20+
project
21+
└─── packages
22+
└─── user-management/
23+
└─── shared/
24+
└─── package.json
25+
└─── registration/
26+
└─── package.json
27+
└─── login/
28+
└─── package.json
29+
```
30+
31+
Inside `project/.eslintrc.json`:
32+
33+
```jsonc
34+
{
35+
// ...
36+
"rules": {
37+
// ...
38+
"workspaces/no-cross-imports": "error"
39+
},
40+
"overrides": [
41+
{
42+
"files": ["packages/user-management/**/*"],
43+
"rules": {
44+
"workspaces/no-cross-imports": [
45+
"error",
46+
{ "allow": ["@project/user-management-shared"] }
47+
]
48+
}
49+
}
50+
]
51+
}
52+
```
53+
54+
### Using cascading configuration files
55+
56+
The [cascading configuration files feature](https://eslint.org/docs/latest/use/configure/configuration-files#cascading-and-hierarchy) of ESLint allows you to create a configuration file in a subdirectory of your project.
57+
58+
> [!WARNING]
59+
> This feature will be deprecated in the next major version of ESLint, see [Flat config rollout plans](https://eslint.org/blog/2023/10/flat-config-rollout-plans).
60+
> It is recommended to use [`overrides`](#using-overrides-recommended) instead.
61+
62+
#### Example
63+
64+
Assuming the following project structure:
65+
66+
```
67+
project
68+
└─── packages
69+
└─── user-management/
70+
└─── shared/
71+
└─── package.json
72+
└─── registration/
73+
└─── package.json
74+
└─── login/
75+
└─── package.json
76+
```
77+
78+
Inside `project/.eslintrc.json`:
79+
80+
```jsonc
81+
{
82+
// ...
83+
"rules": {
84+
// ...
85+
"workspaces/no-cross-imports": "error"
86+
}
87+
}
88+
```
89+
90+
Inside `project/packages/user-management/.eslintrc.json`:
91+
92+
```jsonc
93+
{
94+
"rules": {
95+
"workspaces/no-cross-imports": [
96+
"error",
97+
{ "allow": ["@project/user-management-shared"] }
98+
]
99+
}
100+
}
101+
```

docs/rules/no-cross-imports.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ import bar from "../B/bar";
4747
import foo from "./packages/B/foo";
4848
```
4949

50-
### scopes
50+
### scopes (**DEPRECATED**)
51+
52+
> [!WARNING]
53+
> This feature has been deprecated and will be removed in the next major version.
54+
> For more information, see [Deprecating Scopes](../deprecating-scopes.md).
5155
5256
Takes either a boolean or an options object. Defaults to `false`.
5357

lib/rules/no-cross-imports.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ const filterSharedPackagesInCurrentScope =
5757
return locationArray[locationArray.length - 1] !== scopedSharingFolderName;
5858
};
5959

60+
let scopesDeprecationShown = false;
61+
6062
module.exports.create = (context) => {
6163
const {
6264
options: [{ allow = [], scopes = { enable: false } } = {}],
@@ -66,6 +68,24 @@ module.exports.create = (context) => {
6668
const scopedEnabled = scopes === true || !!scopes.enable;
6769
const scopedSharingFolderName = scopes.folderName || "shared";
6870

71+
/* istanbul ignore if */
72+
if (
73+
scopedEnabled &&
74+
!scopesDeprecationShown &&
75+
process.stdout &&
76+
process.stdout.isTTY
77+
) {
78+
scopesDeprecationShown = true;
79+
80+
console.warn(
81+
"\x1b[1m", // bright
82+
"\x1b[33m", // yellow text
83+
"Warning:",
84+
"\x1b[0m", // reset
85+
"the 'scopes' option of the 'workspaces/no-cross-imports' rule has been deprecated and will be removed in the next major version. See https://github.com/joshuajaco/eslint-plugin-workspaces/blob/main/docs/deprecating-scopes.md for more information.",
86+
);
87+
}
88+
6989
const workspaces = getWorkspaces(context);
7090

7191
if (!workspaces) return {};

0 commit comments

Comments
 (0)