Repository navigation
Description
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
- 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. - 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.
- 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_violationsemits function-scoped records only, and the JSON contract plus both formatters inmain.rs/hooks.rswould 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
- Decide the scoping model (1/2/3): option 1, top-level blocks plus snippets
-
docs/spec.md§Svelte updated - Implementation in
crates/core/src/language.rs - Golden fixtures in
tests/fixtures/svelte/ - Re-scan the private SvelteKit app; template violations point at a block, not
line 1(see fix(svelte): score templates per top-level block and snippet #25) - PR/review: fix(svelte): score templates per top-level block and snippet #25, Astra accepted
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
Activity
docs(spec): turn cyclomatic off by default and score Svelte units