You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -9,190 +9,212 @@ In order to prevent such scenarios this rule allows you to define restricted zon
9
9
10
10
## Rule Details
11
11
12
-
This rule has one option. The option is an object containing the definition of all restricted `zones` and the optional `basePath` which is used to resolve relative paths within.
13
-
The default value for `basePath` is the current working directory.
14
-
15
-
Each zone consists of the `target` paths, a `from` paths, and an optional `except` and `message` attribute.
16
-
17
-
-`target` contains the paths where the restricted imports should be applied. It can be expressed by
18
-
- directory string path that matches all its containing files
19
-
- glob pattern matching all the targeted files
20
-
- an array of multiple of the two types above
21
-
-`from` paths define the folders that are not allowed to be used in an import. It can be expressed by
22
-
- directory string path that matches all its containing files
23
-
- glob pattern matching all the files restricted to be imported
24
-
- an array of multiple directory string path
25
-
- an array of multiple glob patterns
26
-
-`except` may be defined for a zone, allowing exception paths that would otherwise violate the related `from`. Note that it does not alter the behaviour of `target` in any way.
27
-
- in case `from` contains only glob patterns, `except` must be an array of glob patterns as well
28
-
- in case `from` contains only directory path, `except` is relative to `from` and cannot backtrack to a parent directory
29
-
-`message` - will be displayed in case of the rule violation.
12
+
This rule has one option, which is an object containing all `zones` where restrictions will be applied, plus an optional `basePath` used to resolve relative paths within each zone.
13
+
The default for `basePath` is the current working directory.
14
+
15
+
Each zone consists of a `target`, a `from`, and optional `except` and `message` attributes.
16
+
17
+
-`target` - Identifies which files are part of the zone. It can be expressed as:
18
+
- A simple directory path, matching all files contained recursively within it
19
+
- A glob pattern
20
+
- An array of any of the two types above
21
+
-*Example: `target: './client'` - this zone consists of all files under the 'client' dir*
22
+
-`from` - Identifies folders from which the zone is not allowed to import. It can be expressed as:
23
+
- A simple directory path, matching all files contained recursively within it
24
+
- A glob pattern
25
+
- An array of only simple directories, or of only glob patterns (mixing both types within the array is not allowed)
26
+
-*Example: `from: './server'` - this zone is not allowed to import anything from the 'server' dir*
27
+
-`except` - Optional. Allows exceptions that would otherwise violate the related `from`. Note that it does not alter the behaviour of `target` in any way.
28
+
- If `from` is an array of glob patterns, `except` must be an array of glob patterns as well.
29
+
- If `from` is an array of simple directories, `except` is relative to `from` and cannot backtrack to a parent directory.
30
+
-*Example: `except: './server/config'` this zone is allowed to import server config, even if it can't import other server code*
31
+
-`message` - Optional. Displayed in case of rule violation.
32
+
33
+
*Note: The `from` attribute is NOT matched literally against the import path string as it appears in the code. Instead, it's matched against the path to the imported file after it's been resolved against `basePath`.*
30
34
31
35
### Examples
32
36
33
-
Given the following folder structure:
37
+
Given this folder structure:
34
38
35
39
```pt
36
-
my-project
40
+
.
37
41
├── client
38
-
│ └── foo.js
42
+
│ ├── foo.js
39
43
│ └── baz.js
40
44
└── server
41
45
└── bar.js
42
46
```
43
47
44
-
and the current file being linted is `my-project/client/foo.js`.
48
+
And this configuration:
45
49
46
-
The following patterns are considered problems when configuration set to `{ "zones": [ { "target": "./client", "from": "./server" } ] }`:
50
+
```json
51
+
{
52
+
"zones": [
53
+
{
54
+
"target": "./client",
55
+
"from": "./server"
56
+
}
57
+
]
58
+
}
59
+
```
60
+
61
+
:x: The following is considered incorrect:
47
62
48
63
```js
64
+
// client/foo.js
49
65
importbarfrom'../server/bar';
50
66
```
51
67
52
-
The following patterns are not considered problems when configuration set to `{ "zones": [ { "target": "./client", "from": "./server" } ] }`:
68
+
:white_check_mark:The following is considered correct:
53
69
54
70
```js
71
+
// server/bar.js
55
72
importbazfrom'../client/baz';
56
73
```
57
74
58
75
---------------
59
76
60
-
Given the following folder structure:
77
+
Given this folder structure:
61
78
62
79
```pt
63
-
my-project
80
+
.
64
81
├── client
65
-
│ └── foo.js
66
-
│ └── baz.js
82
+
│ └── ...
67
83
└── server
68
84
├── one
69
-
│ └── a.js
85
+
│ ├── a.js
70
86
│ └── b.js
71
87
└── two
88
+
└── a.js
72
89
```
73
90
74
-
and the current file being linted is `my-project/server/one/a.js`.
0 commit comments