Skip to content
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

[Feature request] Multiple types for a file #348

Open
EtienneTurc opened this issue Jan 30, 2025 · 2 comments
Open

[Feature request] Multiple types for a file #348

EtienneTurc opened this issue Jan 30, 2025 · 2 comments
Labels
enhancement New feature or request
Milestone

Comments

@EtienneTurc
Copy link

Is your feature request related to a problem? Please describe.

eslint-plugin-boundaries does not allow a single file to be of multiple types. For instance, if a file is a service with a pattern like user.service.ts and the same file is in a domain with a pattern like domains/user/**, then this file will either be recognized as a service or as part of the domain but not both at the same type.

Why this feature could be useful?

Let's take the following example:

src/
|── domains/
|   |── user/
|   |   |── services/
|   |   |   |── user.ts
|   |   |── person/
|   |   |   |── person.service.ts
|   |   |   |── person.repository.ts
|   |   |── login/
|   |   |   |── login.service.ts
|   |   |   |── login.repository.ts
|   |── planning/
|   |   |── planning.service.ts
|   |   |── planning.repository.ts

In this example, we want to ensure both those conditions:

  • Repository files can't import service files
  • Files inside a domain can't import files of another domain. For instance the file person.service.ts should be able to import user.ts, person.repository.ts and login.service.ts, but it should not be able to import planning.service.ts or planning.repository.ts.

I would like it to work with this configuration:

[
  { type: 'domains', mode: 'full', pattern: ['domains/*/**/*'], capture: ['domainName'] },
  { type: 'services', mode: 'file', pattern: ['*.service.ts', '**/services/**/*'] },
  { type: 'repositories', mode: 'file', pattern: ['*.repository.ts', '**/repositories/**/*'] }
]

Describe alternatives you've considered

I have considered using capturing groups but the fact that files (such as services in my example) could have different patterns (from folder, or based on the extension) makes it hard to correctly capture the nature of the file (ie for this example, either a service or a repository). I know it might be possible, but when you start adding more and more boundaries, it becomes really hard to maintain and adjust them. Moreover, it means, that there is only 1 type defined with a lot of capturing groups which seems to go against the idea of this plugin.
So I would like to avoid this option if possible.

@EtienneTurc EtienneTurc changed the title Multiple types for a file [Feature request] Multiple types for a file Jan 30, 2025
@javierbrea
Copy link
Owner

Hi @EtienneTurc ,
Yes, you are right. This is something that I'm thinking about from time ago. I'm planning to create a new major release based on the concept of "tags", so multiple types can be assigned to each file. This would make the plugin much more flexible and powerful, as you have explained. So, I'll let this issue open to track the work of this feature.

Thank you very much!

@javierbrea javierbrea added the enhancement New feature or request label Feb 3, 2025
@javierbrea javierbrea added this to the 6.0.0 milestone Feb 3, 2025
@EtienneTurc
Copy link
Author

Hi @javierbrea,

Thank you for your answer and your concern about this topic. It would be great if it could be added in the next major release !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants