ArchUnitPython icon indicating copy to clipboard operation
ArchUnitPython copied to clipboard

[FEATURE] Decorator / metaclass-based rules

Open LukasNiessen opened this issue 4 months ago • 0 comments

In short

In Python many things are marked with decorators (@dataclass, @app.route, @inject). Today rules can only match by path or name; this lets a rule target decorated things — e.g. 'everything with @app.route lives in the api folder', or 'no attribute may use the field-injection decorator.'

Problem

Many rules target decorated elements — 'route handlers live in the api layer', 'no attribute uses a field-injection decorator', '@dataclass models belong to the domain'. ArchUnitPython matches on paths and names but cannot assert on decorators today.

Proposal

Add decorator/metaclass predicates onto the existing project_files(...) chain, e.g. project_files("src/").with_decorator("app.route").should().be_in_folder("**/api/**") and project_files("src/").in_folder("**/domain/**").should_not().use_decorator("inject").

Acceptance criteria

  • [ ] .with_decorator("dataclass") selects classes carrying that decorator, including via a meta-decorator.
  • [ ] .should_not().use_decorator("inject") fails on a violating element with a clickable location.
  • [ ] Empty-test protection applies when no decorated elements match.

LukasNiessen avatar Jul 26 '26 20:07 LukasNiessen