Skip to content

[FEATURE] Decorator / annotation-based rules #75

Description

@LukasNiessen

In short

In TS many things use decorators (@Component, @Injectable, @Controller). This lets a rule target decorated things — 'everything with @Controller lives in the web folder', or 'no property may use a field-injection decorator.'

Problem

A large class of architecture rules is naturally expressed against decorators — 'classes decorated with @controller must live in the web layer', 'no property may use field injection (@Inject)', '@entity types belong to the domain'. ArchUnitTS matches on file paths and names but cannot assert on decorators today.

Proposal

Add decorator predicates onto the existing projectFiles(...) chain (class/method/property/parameter, incl. meta-decorators), e.g. projectFiles("src").withDecorator("Controller").should().beInFolder("**/web/**") and projectFiles("src").inFolder("**/domain/**").shouldNot().useDecorator("Inject").

Acceptance criteria

  • .withDecorator("Controller") selects classes carrying that decorator, including via a meta-decorator.
  • .shouldNot().useDecorator("Inject") fails on a violating element with a clickable location.
  • Empty-test protection applies when no decorated elements match.

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions