Question: How to use "scope: folder" for detecting circular imports between folders in a folder
Summary
We have features/libraries in a modules/ folder. We'd like to allow a acyclic dependency graph between the modules while guarding against circular dependencies.
If a file in modules/a/ depends on a file in modules/b/, nothing in modules/b/ can depend on modules/a/.
I noticed that there's a scope option. But I'm unsure how would I configure the rule and I'm looking for some examples.
Context
The following rule configuration leaks outside the /modules/ folder causing them to be included in the "circular" detection. Example error caused by this: /module/a -> /common/ -> /api/ -> /views/ -> /module/a.
{
name: 'no-circular-dependency-between-modules',
comment:
'If a module A depends on module B, then ' +
'module B should not depend on module A',
severity: 'error',
from: {
path: '/modules/([^/]+)'
},
to: {
circular: true,
},
scope: "folder",
},What I'd love to get is some way to confine the scope to only circulars between the /module/ folders. The via examples look like they might provide a fix here, but I'm unsure if scope: "folder" supports via yet.
The full solution we are trying to implement is:
- Forbid acyclic imports between modules
- Forbid all imports between modules, unless explicitly allowed (
acan importb)
Environment
- Version used: latest
- Node version: 18
Source: sverweij/dependency-cruiser