import-js/eslint-plugin-import
View on GitHub`no-restricted-paths` should support negated glob pattern
Open
#2,800 opened on Jun 16, 2023
help wanted
Repository metrics
- Stars
- (4,946 stars)
- PR merge metrics
- (Avg merge 138d 22h) (3 merged PRs in 30d)
Description
Bug Description
We cannot use a negated glob pattern (e.g. '!dir_to_exclude/**') in zone.target, zone.from, and zone.except.
Impact
This prevents us from specifying a target that matches anything except certain files or directories. Fixing the bug should help address the use case requested in #2497 as well.
Root Cause
This is due to path.resolve is used to resolve the glob patterns like a relative path (e.g. '!dir_to_exclude/**' becomes '/home/project_dir/!dir_to_exclude/**'), making it invalid.
Suggested Fix
I'd love to suggest the following fix:
- When constructing a minimatch matcher, instead of resolving the glob patterns as paths, the glob patterns shall be passed as is to minimatch, and
- When matching a path, instead of using the absolute path, the path should be resolved as a relative path to the base path specified in
base.