Skip to content

fix(svelte): score templates per top-level block and snippet - #25

Merged
ElbertePlinio merged 1 commit into
mainfrom
fix/8-svelte-template-units
Sep 27, 2026
Merged

ElbertePlinio merged 1 commit into
mainfrom
fix/8-svelte-template-units

Conversation

@ElbertePlinio

Copy link
Copy Markdown
Member

Closes #8

A Svelte template was scored as one whole-file <template> pseudo-function, so a large page failed at line 1 with a number that grew with file size. This takes option 1 from the issue: each top-level {#if}/{#each}/{#await} block is its own unit at its opening line, with nested blocks counting toward it and adding depth. Every {#snippet} is its own unit wherever it appears and is excluded from the enclosing block, like a nested function. Elements and {#key} are transparent. The root <template> keeps only expressions outside any unit. The rule is in docs/spec.md §Svelte, and units are found by tree-sitter node kinds.

The golden fixture adds a {#key}-wrapped {#each} holding a snippet with its own {#if}. The negative case is that the snippet's decisions are not counted in the {#each}.

Re-scan: across local Svelte repos, 11 former line-1 <template> violations drop to 4, each now pointing at a block (for example pickscribe/src/lib/views/History.svelte:140 {#if} complexity 17, depth 5). The 2675-line page from #6 no longer exists in that form. prova-clara's remaining <template> 28 passes because no single block reaches 15.

Coverage is 92.42% of lines, so the CI floor goes from 89 to 92 per the ratchet.

Touches template traversal in crates/core/src/language.rs, which #7 also changes, so merge the two one after the other.

Validation: cargo test --workspace --locked --all-targets, cargo clippy --workspace --all-targets -- -D warnings, cargo llvm-cov --workspace --locked --fail-under-lines 92, PickCheck over the changed files (only the intentional over-limit fixture functions fail).

A Svelte template was one whole-file <template> pseudo-function, so a
large page failed at line 1 with a score that grew with file size.
Each top-level {#if}/{#each}/{#await} block and every {#snippet} is now
its own unit at its opening line; the root <template> keeps only
expressions outside any block.

Raises the coverage floor to 92 per the ratchet.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant