qossmic / deptrac

Keep your architecture clean.
https://qossmic.github.io/deptrac
MIT License
2.64k stars 134 forks source link

composer doesn't allow to check exclusion from one of the packages #1420

Open pizgariu opened 5 months ago

pizgariu commented 5 months ago
deptrac:
  paths:
    - './src/'
  exclude_files:
    - '#.*[tT]est.php#'
    - '#Kernel\.php$#'
    - '#.*Response.php$#'
  layers:
    - name: Domain
      collectors:
        - type: directory
          value: src/Domain/.*
    - name: Application
      collectors:
        - type: directory
          value: src/Application/.*
    - name: Infrastructure
      collectors:
        - type: directory
          value: src/Infrastructure/.*
    - name: UI
      collectors:
        - type: directory
          value: src/UI/.*
    - name: Shared
      collectors:
        - type: directory
          value: src/Shared/.*
    - name: Symfony
      collectors:
        - type: composer
          composerPath: composer.json
          composerLockPath: composer.lock
          packages:
            - symfony/amqp-messenger
            - symfony/apache-pack
            - symfony/asset
            - symfony/console
            - symfony/doctrine-messenger
            - symfony/dotenv
            - symfony/expression-language
            - symfony/flex
            - symfony/form
            - symfony/framework-bundle
            - symfony/http-client
            - symfony/intl
            - symfony/mailer
            - symfony/mime
            - symfony/monolog-bundle
            - symfony/notifier
            - symfony/process
            - symfony/property-access
            - symfony/property-info
            - symfony/proxy-manager-bridge
            - symfony/runtime
            - symfony/security-bundle
            - symfony/serializer
            - symfony/string
            - symfony/translation
            - symfony/twig-bundle
            - symfony/uid
            - symfony/validator
            - symfony/web-link
            - symfony/webpack-encore-bundle
            - symfony/yaml
    - name: SymfonyValidator
      collectors:
        - type: classLike
          value: 'Symfony\\Component\\Validator\\Constraint'
  ruleset:
    Shared:
      - Symfony
    Domain:
      - Shared
    Application:
      - Domain
      - Shared
      # TODO: Symfony are ONLY allowed in the Application layer cause we use DTOs and Symfony Validator which violates the ruleset, need to allow ONLY for this package
#      - Symfony
      - SymfonyValidator
    Infrastructure:
      - Application
      - Domain
      - Shared
      - Symfony
      - UI
    UI:
      - Infrastructure
      - Application
      - Domain
      - Shared
      - Symfony
      - SymfonyValidator
  formatters:
    graphviz:
      hidden_layers:
        - Symfony

If we switch to the Symfony this will work, but also could include ALL from Symfony packages which is not good for onion architecture. Can You please explain me if this is a bug or maybe I don't know how to work with deptrac :)

Thanks for any help!

PS. I've found attribute and I was sure that was the collector what I was looking for - its for Assert fot DTO's. But with this config it's still not working & duplicate same errors:

    - name: SymfonyValidator
      collectors:
        - type: attribute
          value: 'Symfony\Component\Validator\Constraints'
pizgariu commented 5 months ago

image

May I use to write my own attribute check if this not working? Can anyone reproduce? My DTO class:

<?php

namespace MiningCity\DirectMiningService\Application\Post\DTO\Request;

use Symfony\Component\Validator\Constraints as Assert;

final class UpdatePostRequest
{
    #[Assert\NotBlank]
    #[Assert\Type('string')]
    #[Assert\Length(min: 10)]
    public string $content;

    public ?\DateTime $publishedAt = null;
}

When I use this extra later and additionaly remove it from Symfony composer collector shows issues on two layers used on Application.

pizgariu commented 5 months ago

I think I get it - You check for ClassLikeReference or FunctionReference, but I can't see any ClassPropertyReference... Am I right?