Skip to content

Svelte templates are scored as one whole-file pseudo-function #8

Closed

Description

@ElbertePlinio

Parent: #6

A Svelte template is currently measured as a single <template> pseudo-function, so a whole file's control flow accumulates into one score.

Evidence

From the private SvelteKit app scan (#6), 12 of 44 violations are <template>:

File Metric Value Limit
route page A complexity 137 15
route page B complexity 48 15
component A complexity 45 15
component B complexity / depth 22 / 5 15 / 4

Route page A is 2675 lines with 94 {#if}/{#each}/{#await} blocks. Markup has no function boundaries, so collect_functions yields one node for the entire template and every block in the file adds to the same counter.

Problem

A per-function limit applied to a whole-file metric is not actionable. The violation reports line 1 and says, in effect, "this template is large" — an agent receiving this from the hook has no specific target to refactor, and the number scales with file size rather than with reading difficulty. It also means one large route file permanently blocks the hook for any edit anywhere in it.

Options

  1. Score per top-level block or {#snippet} — closest to the per-function model; gives an actionable line number. Needs a rule for what counts as a template "unit" and how nested blocks attribute.
  2. Separate Svelte template limits — keep whole-template scoring but give it its own (much higher) limits via the existing per-language override mechanism. Cheap, but preserves the un-actionable report.
  3. Treat template size as a file-level metric — honest about what is being measured, but requires the file-scoped violation axis that does not exist yet (add_violations emits function-scoped records only, and the JSON contract plus both formatters in main.rs/hooks.rs would change).

Option 1 is the likely answer; decide before implementing. Whichever is chosen goes into docs/spec.md (§Svelte) first.

Notes

  • Interacts with Per-language metric registry + cognitive complexity #7: cognitive complexity needs its own Svelte template rules, and both changes touch template traversal in crates/core/src/language.rs. Serialize the merges.
  • AGENTS.md: never classify template syntax by text prefixes — use node kinds.

Checklist

Validation

cargo test --workspace --locked --all-targets
cargo clippy --workspace --all-targets -- -D warnings
cargo llvm-cov
complexity-gate check --format json <private-svelte-app>/src

Status: In review (#25)
Next action: CI and merge

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions