import-js / import-js/eslint-plugin-import

no-restricted-paths improve `except`

Open
#1,701 2 comments 9 reactions 0 assignees View on GitHub
enhancement help wanted
Dominant language
JavaScript
Stars
5.9k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

Hey I have a suggestion on how to improve the `except` option of the _import/no-restricted-paths_ rule (and I'm happy to implement it if you think it is a good idea).

Let me start with my **use case**:

```
my-project
├── client
│ └── foo.js
│ └── baz.js
└── server
└── bar
└── index.js
└── types.js
```

I can use this rule to forbid importing server-only files in my client code. That is nice. But at the same time I also still want to allow to **import from type files** even though they are in the server directory and this is where I'm limited, because I can currently only pass a path to `except`.

Instead I would love to either pass a glob pattern like this

``` js
// solution proposal 1
{ "zones": [ {
"target": "./client",
"from": "./server",
"except": ["./**/types"]
} ] }
```

...or a regex would also work:

``` js
// solution proposal 2
{ "zones": [ {
"target": "./client",
"from": "./server",
"except": [/types/]
} ] }
```

Let me know what you think.
I know that #1662 might want to try to solve a similar issue, but I think it is not the same, but could still solve what @vladimiry wanted to achieve. I don't know his use case though.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the existing import/no-restricted-paths rule and how its except option is handled. Decide whether glob patterns or regular expressions fit the rule's configuration, then verify that client imports from server paths can allow matching type files without weakening other restrictions.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, javascript
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.