import-js / import-js/eslint-plugin-import
Enhancement: [import/no-restricted-paths] accept target exceptions
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 5.9k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/rules/no-restricted-paths.js, especially the zone schema and matchingZones filter shown in the issue. Check how target paths are matched, then verify that string and array exceptTarget values exclude matching target paths while ordinary targets remain restricted; add or update the relevant rule coverage if the repository provides it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- eslint, javascript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100