Skip to content

[FEATURE] Decorator / metaclass-based rules #42

Description

@LukasNiessen

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions