You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thank you for this great tool! It took me a while to build two specific rules, and since I had to look through issues to find an answer, I figured my solution could be useful for others. Specifically I wanted rules that a src/feature folder can only depend on itself or on modules outside of src/features (but not one feature to another). And except two specific modules, no module is allowed to depend on any src/feature folder.
Context
The context is a React app with a src/App.tsx that does a lot of imports from folders in src/features/ folders. The App is allowed to import these features, but nothing else should like (src/components). And each feature should be standalone, and only depend on shared components (e.g. src/components).
I eventually managed to put these rules together:
forbidden: {{name: 'not-into-features',comment:
'Code outside of features should not depend on features, except App and Shell',severity: 'error',from: {pathNot: ['^src/features','^src/App','^src/Shell']},to: {path: '^src/features'},},{name: 'features-not-to-features',comment:
'One feature should not depend on another feature (in a separate folder)',severity: 'error',from: {path: '(^src/features/)([^/]+)/'},to: {path: '^$1',pathNot: '$1$2'},},}
I've been toying with expanding the documentation in this respect (looking for inspiration to http-proxy-middleware's 'recipes'), but was doubting it'd actually fill a need - as as an author it's one of my blind spots. This is why your feedback is very valuable. Thank you!
I'll expand the documentation with a bunch of examples/ recipes, starting with yours!
Summary
Thank you for this great tool! It took me a while to build two specific rules, and since I had to look through issues to find an answer, I figured my solution could be useful for others. Specifically I wanted rules that a src/feature folder can only depend on itself or on modules outside of src/features (but not one feature to another). And except two specific modules, no module is allowed to depend on any src/feature folder.
Context
The context is a React app with a
src/App.tsx
that does a lot of imports from folders insrc/features/
folders. The App is allowed to import these features, but nothing else should like (src/components). And each feature should be standalone, and only depend on shared components (e.g. src/components).I eventually managed to put these rules together:
Example violations:
The first rule was relatively easy, but the 2nd rule was rather difficult to write, and I only managed after reading #330 (comment)
Maybe these could be useful examples for others, e.g. on https://github.com/sverweij/dependency-cruiser/blob/develop/doc/rules-tutorial.md where its going to be easier to find than in issues.
The text was updated successfully, but these errors were encountered: