Closed butzist closed 11 months ago
Hi @butzist , when the imported library is outside the project it is considered "external", so, you should use the external rule to allow or disallow imports. You can configure it also using micromatch patterns, or even allow/disallow importing specific variables when using destructured imports.
Thank you for your answer @javierbrea - I have tried micromatch patterns, but it seems like they are only applied to the package name and not to the esm path inside the package. An example:
I have the following piece of code:
The following rule unfortunately does not result in a eslint error:
"boundaries/external": [
"error",
{
default: "allow",
rules: [
{
from: ["components"],
disallow: ["@datahow/dhljs/services/**/*"],
},
],
},
],
whereas the following rule works, but seems to be only matching on the package name - not on the path:
"boundaries/external": [
"error",
{
default: "allow",
rules: [
{
from: ["components"],
disallow: ["@datahow/*"],
},
],
},
]
results in:
Hi @butzist , sorry, you're right, it only takes into account the module name. In order to avoid a breaking change, I'm adding a path
option that may be used to match the module path using micromatch patterns. For example:
{
"boundaries/external": [
"error",
{
default: "allow",
rules: [
{
from: ["components"],
disallow: [
["@datahow/dhljs", { path: "/services/*" }]
],
},
],
},
],
}
Awesome, thanks a lot @javierbrea! Will test this today.
Thanks to you for reporting the issue @butzist . Note that the rule documentation was also updated 😉 .
Thanks a lot for this plugin - it has been very useful so far. I have a question though related to the following usecase:
We are moving some elements to a shared library and would like to enforce the same rules, that we have inside the sources, e.g. from: "components", disallow: "repositories".
This is what I came up with so far - which is not working:
Is there any way to specify the allowed paths in a module?