fix(linter/eslint/no-unassigned-vars): skip Svelte and Vue files - #26042
Open
hamodywe wants to merge 1 commit into
Open
fix(linter/eslint/no-unassigned-vars): skip Svelte and Vue files#26042hamodywe wants to merge 1 commit into
hamodywe wants to merge 1 commit into
Conversation
Oxlint parses only the `<script>` blocks of `.svelte` and `.vue` files, so
a binding that the template assigns looks, from the script alone, like it
is declared and read but never assigned. `no-unassigned-vars` then reports
it as always `undefined`.
The reported case is a Svelte element reference:
<script lang="ts">
let dialog: HTMLDialogElement;
function openDialog() { dialog.showModal(); }
</script>
<dialog bind:this={dialog}>Hello</dialog>
Svelte assigns the element to `dialog` on mount. Vue has the same shape:
a `<script setup>` `let` is a `setup-let` binding that `v-model="x"` and
inline handlers such as `@click="x = 1"` assign to directly.
`prefer-const` already skips both extensions for this exact reason, so
this applies the sibling rule's `should_run` guard rather than inventing
one. `.astro` is left alone: its templates cannot write back to a
frontmatter binding.
Closes oxc-project#26038
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Merging this PR will not alter performance
Comparing Footnotes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #26038.
no-unassigned-varsis acorrectnessrule, so this fires by default with no config:Why the rule cannot get this right today
The rule's decision is
has_read && no reference is_write(), taken over the symbol's references in the current script block. Oxlint reaches.svelte/.vuethroughPartialLoader, which extracts the<script>blocks and throws the markup away before parsing — so the template's write is not in the AST the rule sees, and no reference ondialogis ever a write. Every ingredient of the diagnostic is satisfied, and the diagnostic is still wrong: Svelte assigns the element todialogon mount.The same shape exists in Vue, where a
<script setup>letis asetup-letbinding thatv-model="x"and inline handlers such as@click="x = 1"compile to direct assignments against.This is not a matter of tightening the check — the write is in a part of the file the linter never parses.
The change
prefer-consthit exactly this and already skips both extensions (#25148):This applies the sibling rule's guard rather than inventing one, and documents it in the rule docs under an
#### Ignored Filesheading, matchingprefer-const's wording..astrois deliberately not included: an Astro template renders a frontmatter binding but has no construct that writes back to it, so the false positive does not arise there.prefer-constdrew the same line.Scope, stated honestly
This trades a false positive for lost coverage: a genuinely unassigned variable inside a
.svelte/.vue<script>block is no longer reported. That matches the precedent and the reporter's own request, and acorrectnessfalse positive that fires on the documented Svelte idiom costs more than the missed report. Restoring coverage needs template-aware analysis, which is the language-support effort tracked separately (#13017, #17991).Verification
cargo test -p oxc_linter --lib— 1254 passed, 0 failed.test_svelteandtest_vue, cover the reported repro,bind:value, a two-<script>Svelte component,v-model, and an inline@clickhandler.should_runremoved and the tests kept, exactly those two tests fail and the rest pass. The failure output reproduces the reported diagnostic verbatim, including thelet sharedcase from the two-script component — so the tests fail for the right reason, not because the fixture path changed.cargo clippy -p oxc_linter --lib --all-features— no new findings (the twoFromIterator::from_iterwarnings are pre-existing, intsgolint.rsandlib.rs).cargo fmt --checkclean.docs_rule_pages.snap, so the doc addition needs no snapshot regeneration.Built and tested on Windows with the
1.97.1-x86_64-pc-windows-gnutoolchain rather than the pinned1.98.0, and withRUSTFLAGSoverridden to drop the MSVC-only link args that.cargo/config.tomlapplies to everytarget_os = "windows"target. Nothing in the repository was changed for that.Written with AI assistance (Claude Code), reviewed and tested by me before submitting, per AGENTS.md.