Skip to content

linter: eslint/prefer-const incorrectly flagging variable in Svelte file #19470

@peterreeves

Description

@peterreeves

What version of Oxlint are you using?

1.48.0

What command did you run?

oxlint -c ./.oxlintrc.json

What does your .oxlintrc.json config file look like?

{
    "rules": {
        "prefer-const": ["warn", { "destructuring": "all" }]
    }
}

(Truncated to contain only relevant rule)

What happened?

Given this input Svelte file:

<script lang="ts">
    let divEl: HTMLElement | null = $state(null);
</script>

<div bind:this={divEl}></div>

Oxlint outputs:

  ⚠ eslint(prefer-const): `divEl` is never reassigned.
   ╭─[Example.svelte]
   │<script lang="ts">
   │     let divEl: HTMLElement | null = $state(null);
   ·         ─────
   │ </script>
   ╰────
  help: Use `const` instead.

But the variable is actually written to by the bind:this part of the template.
Applying Oxlint's suggestion/auto-fix switching from let to const produces a TypeScript error:

Cannot assign to 'divEl' because it is a constant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions