Repository navigation
fix(core): scope-aware shadow tracking for CORRECT004/CORRECT005 - #141
Conversation
#140) Both collectStateWrites (CORRECT004) and collectPropMutations (CORRECT005) matched writes by base identifier name alone, with no scope resolution — a nested local that reused a tracked $state/prop's name was misattributed as writing the outer binding. For CORRECT005 this was a false positive (mutating an unrelated local flagged as a prop violation); for CORRECT004 it was a false negative (a shadowed write made a genuinely-constable $state look mutated, suppressing the finding). Adds a shared walkScoped/scopeIntroducedNames utility that threads a "shadowed names" set down through scope-introducing constructs while walking: function/arrow-function parameters, a catch clause's parameter, a block's own let/const declarations, a for/for-of/for-in loop's declared variable, and a Svelte {#each ... as x} block's context. Both collectors now check the current shadow set before treating an identifier match as real. This extends PR #139's partial fix (function params + each-context only) to also cover block-scoped let/const and for-loops, and applies the same guard to CORRECT004 for consistency. {#snippet}/{:then}/{:catch} bindings remain untracked — documented as a known, deliberately partial mitigation in code comments and the CORRECT005 rule docs (en/ja), not full lexical scope resolution. Fixes #140 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis PR adds scope-aware AST traversal ( ChangesScope-aware shadow tracking
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
Fixes #140 — the follow-up filed from CodeRabbit's review on #139. Extends that PR's partial shadow-tracking fix (function parameters +
{#each}context only, applied only to CORRECT005) into a shared utility applied consistently to both affected rules, with wider coverage.Both
collectStateWrites(CORRECT004) andcollectPropMutations(CORRECT005) matched writes by base identifier name alone, with no scope resolution — a nested local that reused a tracked$state/prop's name was misattributed as writing the outer binding:$statelook mutated, silently suppressing the finding).Fix
A new shared
walkScoped/scopeIntroducedNamesutility threads a "shadowed names" set down through scope-introducing constructs while walking: function/arrow-function parameters, acatchclause's parameter, a block's ownlet/constdeclarations, afor/for-of/for-inloop's declared variable, and a Svelte{#each ... as x}block's context. Both collectors now check the current shadow set before treating an identifier match as real, replacing the plainwalkEstreethey used before.{#snippet}/{:then}/{:catch}bindings remain untracked — genuinely rarer as a real-world collision, and determining their exact AST shape would expand this into full lexical scope resolution (the "heavy lift" CodeRabbit itself flagged). Documented as a known, deliberately partial mitigation in code comments and the CORRECT005 rule docs (en/ja).Test plan
$statecorrectly when only a shadowing function param /{#each}var /for-loop var writes the local, not the state; CORRECT005 doesn't flag mutation of a block-scopedlet/const,for-loop variable, orcatch-clause parameter that shadows the prop, while still flagging the real prop mutation elsewhere in the same file.pnpm build && pnpm typecheck && pnpm test && pnpm lint: all pass (core 372, cli 345, vite 84, mcp 13 — no regressions across the rest of the suite, including all pre-existing CORRECT001–004 tests).pnpm --filter docs check: 0 errors.@svelte-vitals/core+svelte-vitals(precision fix to shipped rules).🤖 Generated with Claude Code
Summary by CodeRabbit
CORRECT005warnings are triggered or suppressed, including additional shadowing cases.