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

Allow Transitive Dependencies #202

Closed
1ma opened this issue Dec 10, 2018 · 3 comments · Fixed by #579
Closed

Allow Transitive Dependencies #202

1ma opened this issue Dec 10, 2018 · 3 comments · Fixed by #579

Comments

@1ma
Copy link

1ma commented Dec 10, 2018

Problem

deptrac only allows explicit dependencies listed in the ruleset and sometimes the list can get quite unwieldly, especially when there's lots of layers (e.g. a DDD project with 3 layers per bounded context and upstream relations). In these situations it would be handy if deptrac allowed transitive dependencies (IOW if B can depend on A and C can depend on B then C should be able to depend on A, too).

Since this would be a breaking change it could be implemented as a command flag (something like --allow-transitive-deps). Thoughts?

Example

paths:
  - ./src

layers:
  - name: Domain
    collectors:
      - type: className
        regex: ^Domain\\.*
  - name: Application
    collectors:
      - type: className
        regex: ^Application\\.*
  - name: Infrastructure
    collectors:
      - type: className
        regex: ^Infrastructure\\.*

ruleset:
  Domain:
  Application:
    - Domain
  Infrastructure:
    - Application
// src/Infrastructure/Controller.php

namespace Infrastructure;

class Controller
{
    public function __invoke()
    {
        new \Domain\Entity();
    }
}
$ php vendor/bin/deptrac 

deptrac is alpha, not production ready.
please help us and report feedback / bugs.

Start to create an AstMap for 3 Files.
...
AstMap created.
start emitting dependencies "InheritanceDependencyEmitter"
start emitting dependencies "BasicDependencyEmitter"
end emitting dependencies
start flatten dependencies
end flatten dependencies
collecting violations.
formatting dependencies.
Infrastructure\Controller::11 must not depend on Domain\Entity (Infrastructure on Domain)

Found 1 Violations

Desired output:

$ php vendor/bin/deptrac 

deptrac is alpha, not production ready.
please help us and report feedback / bugs.

Start to create an AstMap for 3 Files.
...
AstMap created.
start emitting dependencies "InheritanceDependencyEmitter"
start emitting dependencies "BasicDependencyEmitter"
end emitting dependencies
start flatten dependencies
end flatten dependencies
collecting violations.
formatting dependencies.

Found 0 Violations

PS related, but vague-r issue: #158

@josefsabl
Copy link

It could be useful for some architectures. I think this would, however, be better if you could specify this in the ruleset, not as a global flag. Parts of your system may have different rules.

@MartinMystikJonas
Copy link

Maybe this could be somehow specified in rules. Like "Application" means only Application and "+Application" means Application plus all layers Application can depend on.

@smoench
Copy link
Contributor

smoench commented Feb 26, 2021

I would be fine with this notation. Does anyone want to provide a PR?

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

Successfully merging a pull request may close this issue.

4 participants