Skip to content

Commit fde081b

Browse files
author
Rebecca Stevens
committed
feat(no-restricted-paths): add option allowedImportKinds
fix #1899
1 parent d407f36 commit fde081b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/rules/no-restricted-paths.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ import isStaticRequire from '../core/staticRequire'
66
import docsUrl from '../docsUrl'
77
import importType from '../core/importType'
88

9+
const allowedImportKindsSchema = {
10+
type: 'array',
11+
items: {
12+
type: 'string',
13+
},
14+
uniqueItems: true,
15+
}
16+
917
module.exports = {
1018
meta: {
1119
type: 'problem',
@@ -32,12 +40,14 @@ module.exports = {
3240
},
3341
uniqueItems: true,
3442
},
43+
allowedImportKinds: allowedImportKindsSchema,
3544
message: { type: 'string' },
3645
},
3746
additionalProperties: false,
3847
},
3948
},
4049
basePath: { type: 'string' },
50+
allowedImportKinds: allowedImportKindsSchema,
4151
},
4252
additionalProperties: false,
4353
},
@@ -48,6 +58,7 @@ module.exports = {
4858
const options = context.options[0] || {}
4959
const restrictedPaths = options.zones || []
5060
const basePath = options.basePath || process.cwd()
61+
const allowedImportKinds = options.allowedImportKinds || []
5162
const currentFilename = context.getFilename()
5263
const matchingZones = restrictedPaths.filter((zone) => {
5364
const targetPath = path.resolve(basePath, zone.target)
@@ -101,6 +112,13 @@ module.exports = {
101112
return
102113
}
103114

115+
const typeIsExpected = (zone.allowedImportKinds || allowedImportKinds)
116+
.some((kind) => node.parent && kind === node.parent.importKind)
117+
118+
if (typeIsExpected) {
119+
return
120+
}
121+
104122
context.report({
105123
node,
106124
message: `Unexpected path "{{importPath}}" imported in restricted zone.${zone.message ? ` ${zone.message}` : ''}`,

0 commit comments

Comments
 (0)