|
| 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 | +``` |
0 commit comments