Skip to content

Jinja/Django templates get roles: ["unknown"] — adopt Java's view-template #214

Description

@rahlk

Is your feature request related to a problem? Please describe.

codeanalyzer/artifacts/discovery.py's RULES table has no row for any template file, so every rendered view in a Django/Flask/FastAPI project lands in application.artifacts{} with format: "text", roles: ["unknown"]. The record itself is complete (source, sha256, size_bytes, correct repo-relative key) — what is missing is the one field a consumer would filter on to ask "what are this application's views?".

roles[] is where that answer belongs: dependency-manifest and tool-config are already assigned by exactly this kind of extension/name recognition.

Describe the solution you'd like

  • Add RULES rows assigning roles: ["view-template"] for the Python-ecosystem template extensions: *.jinja, *.jinja2, *.j2, *.mako, *.tpl, and .html/.htm under a templates/ directory.
  • format names the template language, one value per family (java and TS both do this: jsp/xhtml/html, ejs/handlebars/pug/…). Verify a new format value is inert in the config-key dispatch (in TS the switch default returns []).
  • Confirm no bare *.html catch row is added. In TS, matchRules unions roles across every matching rule, so a catch row would ride unknown along on the convention-directory rows; check whether python's matcher has the same union behaviour before assuming it is safe.
  • Test: a fixture with each extension asserts the role, and asserts a .md/.toml artifact does not get it, and that a bare index.html outside templates/ stays unknown.
  • Record the adoption (not a coining) in whatever decision log this repo keeps, naming java as the origin.

Describe alternatives you've considered

Not stated in the original issue.

Additional context

The role name is already coined — adopt, do not re-coin

codeanalyzer-java coined view-template first, in ArtifactDiscovery.java (its JSP/JSPX/JSPF/tag/tagx/xhtml/Thymeleaf rows). codeanalyzer-typescript adopted that exact spelling in its #208 (src/artifacts/rules.ts, rows for .ejs/.hbs/.pug/.njk/.liquid/.vue/.svelte/.astro plus convention-directory .html). Python is the third analyzer to reach this and should take the same string verbatim — a term coined twice is permanently wrong.

Java's .html policy, adopted by TS, applies here too

A bare *.html gets no role: a static page and a rendered template are not distinguishable by file name. The role is assigned only under a convention directory. Java uses */templates/*.html and */WEB-INF/*.html; TS uses **/views/**/*.{html,htm} and **/templates/**/*.{html,htm}. Django's own convention is templates/, and Flask's is templates/ as well, so the directory rule carries over almost unchanged.

Note the glob semantics differ per analyzer — java's * crosses /, TS's does not (** is required there). Match whatever discovery.py's own matcher means rather than copying a pattern string across languages.

Caveats and known risks

  • Extension-based recognition will mislabel a hand-written .html test input under a templates/ directory as a view. Acceptable — roles[] is best-effort classification and the artifact record is unchanged either way — but say so in the code comment rather than implying precision.
  • This is roles only: no template parsing, no symbol_table entry for a template, no modeling of {{ }} expressions. Those are structural and belong on the design rung.
  • No contract move expected: roles[] is an existing list[str] gaining new values, the same class as a new framework value in the entrypoint pass. The schema snapshot must come out byte-identical — if it does not, stop and escalate.

Definition of done

A fixture containing each listed extension produces artifacts whose roles[] carries view-template, a bare index.html outside templates/ still carries unknown, a non-template artifact is unaffected, the adoption is recorded with java named as the origin, and the schema snapshot is byte-identical.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions