Eslint-plugin-import: no-restricted-paths improve `except`

Created on 26 Mar 2020  ยท  2Comments  ยท  Source: benmosher/eslint-plugin-import

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

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

...or a regex would also work:

// 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.

enhancement help wanted

Most helpful comment

It sounds totally reasonable for a glob pattern to work in the except array.

All 2 comments

It sounds totally reasonable for a glob pattern to work in the except array.

I'm also looking for this feature for the same issue: I want to except type files. Is https://github.com/benmosher/eslint-plugin-import/pull/1708 abandoned? Most of the work seems to have been done, it's sad not to finalize it

Was this page helpful?
0 / 5 - 0 ratings