Open
Description
In order to support more complex use-cases, it would be really nice to be able to exclude parts of the target path.
Suggested config:
zones: [
{
target: './common',
exceptTarget: './common/tests',
from: './features',
message: 'Avoid importing from features.'
}
]
It could be implemented pretty simple by extending the matchingZones
filter:
diff --git a/src/rules/no-restricted-paths.js b/src/rules/no-restricted-paths.js
index 75952dd0..22e06a52 100644
--- a/src/rules/no-restricted-paths.js
+++ b/src/rules/no-restricted-paths.js
@@ -53,0 +54,11 @@ module.exports = {
+ exceptTarget: {
+ anyOf: [
+ { type: 'string' },
+ {
+ type: 'array',
+ items: { type: 'string' },
+ uniqueItems: true,
+ minLength: 1,
+ },
+ ],
+ },
@@ -92 +103,4 @@ module.exports = {
- .some((targetPath) => isMatchingTargetPath(currentFilename, targetPath)),
+ .some((targetPath) => isMatchingTargetPath(currentFilename, targetPath))
+ && ![].concat(zone.exceptTarget || [])
+ .map((except) => path.resolve(basePath, except))
+ .some((exceptPath) => isMatchingTargetPath(currentFilename, exceptPath)),
This would also resolve #2800