-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new rule or replace no-restricted-paths #1132
Comments
Since you can override rules by glob path, or with nested eslintrcs, I'm not sure this is needed. Have you tried that? |
I think I can achieve that with nested eslintrcs and decentralized approach is good for some use cases. But it introduce a lot of management complexity to add (easy to forget), maintain and change rules. From my point of view, nested eslintrcs are good for overriding some rules or settings, but not to enforce structure like described above. For us, it's better do disallow internal access by default and allow only desired layers, modules and/or individual files. While described approach is very powerful and used in the wild (spring security, for example), it maintain a reasonable level of complexity. Again, from my perspective. |
If you don't want nested eslintrcs, you can use glob-based configuration to centralize the configuration in one file. |
Thanks, you are right about glob-based configuration! But I'm struggling to get it right. Because there is only "block" and no allow rule, it can be very complex. For testing I have rule:
I'm expecting, that all
Is there any example how to get it right? Here I get just opposite (click on "switch to unit test and then run). Overall, I think to define a bunch of rules with Another thing is, that used contains-path introduces a breaking change and doesn't support regexp anymore:
Currently, eslint-plugin-import uses |
|
I know, but that's not the point. The point is, that |
That’s fine, we can keep using the old one forever. There’s no reason that deps have to be updated, if they work. |
I don't think that keep old version forever is a good approach for development. Especially, if I look inside of contains-path. Anyway, I've created sophisticated rule to make above things possible and tested it against my requirements. I don't published it now. Following outcome I have:
where
@ljharb is there any interest for pull request? If (hopefully :D) yes, then how I should name the rule? currently I named it |
It’s a fine approach; there’s nothing inherently valuable about upgrading abstractions. I still am not convinced that a separate rule is warranted here. How is glob overrides in your root eslintrc insufficient? |
Globs are working on its own. But to define desired rules leads to very complex regular expressions and in the end, I don't get it working with Therefore, my proposal, which avoids complex regular expressions and introduce new features. It must not be a separate rule. Sure, |
I’m not even sure this use case should be supported, to be honest - why are your restrictions so complex? How can your developers hope to understand the rationale, even if the linter enforces it? |
We create an app with distinct, swappable, layers in each module. Therefore, it's important to ensure access/import pattern of these layers. |
If they’re distinct, shouldn’t they be separate packages (or in a monorepo, separate top-level directories)? |
Distinct in sense we have |
I need more sophisticated rules to restrict the import paths. For example, I have following package structure:
My rules are:
auth/api
can import fromauth/entities
andcommon/api
onlyauth/core
can import fromauth/api
andauth/entities
only*/entities
can't import anything, except other entitiesauth/ui
can import fromauth/core
onlyindex.tsx
can import anything, except*/api/*
I can imagine following rules:
Some considerations:
Any thoughts on this? Would a pull request desirable?
Maybe relevant: #834
The text was updated successfully, but these errors were encountered: