@@ -6,6 +6,14 @@ import isStaticRequire from '../core/staticRequire'
6
6
import docsUrl from '../docsUrl'
7
7
import importType from '../core/importType'
8
8
9
+ const allowedImportKindsSchema = {
10
+ type : 'array' ,
11
+ items : {
12
+ type : 'string' ,
13
+ } ,
14
+ uniqueItems : true ,
15
+ }
16
+
9
17
module . exports = {
10
18
meta : {
11
19
type : 'problem' ,
@@ -32,12 +40,14 @@ module.exports = {
32
40
} ,
33
41
uniqueItems : true ,
34
42
} ,
43
+ allowedImportKinds : allowedImportKindsSchema ,
35
44
message : { type : 'string' } ,
36
45
} ,
37
46
additionalProperties : false ,
38
47
} ,
39
48
} ,
40
49
basePath : { type : 'string' } ,
50
+ allowedImportKinds : allowedImportKindsSchema ,
41
51
} ,
42
52
additionalProperties : false ,
43
53
} ,
@@ -48,6 +58,7 @@ module.exports = {
48
58
const options = context . options [ 0 ] || { }
49
59
const restrictedPaths = options . zones || [ ]
50
60
const basePath = options . basePath || process . cwd ( )
61
+ const allowedImportKinds = options . allowedImportKinds || [ ]
51
62
const currentFilename = context . getFilename ( )
52
63
const matchingZones = restrictedPaths . filter ( ( zone ) => {
53
64
const targetPath = path . resolve ( basePath , zone . target )
@@ -101,6 +112,13 @@ module.exports = {
101
112
return
102
113
}
103
114
115
+ const typeIsExpected = ( zone . allowedImportKinds || allowedImportKinds )
116
+ . some ( ( kind ) => node . parent && kind === node . parent . importKind )
117
+
118
+ if ( typeIsExpected ) {
119
+ return
120
+ }
121
+
104
122
context . report ( {
105
123
node,
106
124
message : `Unexpected path "{{importPath}}" imported in restricted zone.${ zone . message ? ` ${ zone . message } ` : '' } ` ,
0 commit comments