import-js/eslint-plugin-import

no-restricted-paths improve `except`

Open

#1701 aperta il 26 mar 2020

Vedi su GitHub
 (2 commenti) (9 reazioni) (0 assegnatari)JavaScript (1540 fork)batch import
enhancementhelp wanted

Metriche repository

Star
 (4946 star)
Metriche merge PR
 (Merge medio 138g 22h) (3 PR mergiate in 30 g)

Descrizione

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.

Guida contributor