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

[Advice]: Using eslint to prevent dependencies from Domain to Adapters #4

Open
Hyzual opened this issue Feb 7, 2022 · 1 comment
Open

Comments

@Hyzual
Copy link

Hyzual commented Feb 7, 2022

Hello 👋

I've seen your talk at SnowCamp 2022 and I asked if you used any tools to prevent breaking the rule of the Domain dependencies: no dependencies from Domain to the outside world. I think there is actually a tool that can help with that: eslint and one of its plugins, eslint-plugin-import. You probably already know eslint which is widely-used to lint files and detect problems. eslint-plugin-import has many rules but one rule is of particular interest to this problem: import/no-restricted-paths. It allows you to define "zones" from either a folder or a glob, and define specific restrictions on each zone. You can prevent files from one folder from importing files from other defined folders. Using this rule, we can prevent the Domain from importing files from the Adapters.

Shortly before the talk, I watched your video "Hands-on Front : La clean architecture dans le web" and was really inspired to give it a try. I did not go for the full "Clean Architecture", just "Hexagonal Architecture" for now. Anyway, please check out this example of an .eslintrc file that defines rules to prevent dependencies from the Domain to the Adapters. There are also separate rules for each "type" of adapters to prevent adapters from the UI depending directly on other adapters from REST API for example.
The rules do not prevent all dependencies though: you are still allowed to depend on libs from node_modules. If one wants to completely isolate the Domain from libs, the rule should be refined to make it stricter.

I hope this can help ! 🙂

@mchoraine
Copy link
Contributor

Great ! Thanks for your feedback. I'll try to tests eslint rule for domain dependency rule.
Don't hesite to contribute if you feel you can help ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants