eslint-plugin-svelte icon indicating copy to clipboard operation
eslint-plugin-svelte copied to clipboard

feat: Add svelte/prefer-const rule that excludes reactive variables

Open bfanger opened this issue 1 year ago • 2 comments

The const declaration creates an immutable reference to a value. The variable identifier cannot be reassigned. You should understand const declarations as "create a variable whose identity remains constant"

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const

The ESLint prefer-const doesn't take into account that Svelte's reactivity system is reassigning reactive variables. The svelte/prefer-const rule skip variables that are created by runes like $props, $derived, $derived.by, etc.

Companion to the rune-prefer-let rule.

bfanger avatar Jul 06 '24 11:07 bfanger

🦋 Changeset detected

Latest commit: 5c29c5cc180f8e72843eaf58ecb6ad92b760ae5f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-svelte Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Jul 06 '24 11:07 changeset-bot[bot]

Could you please propose the rule in a new issue first?

ota-meshi avatar Jul 06 '24 11:07 ota-meshi

@ota-meshi and @baseballyama, we could close this PR already.

mikededo avatar Dec 31 '24 08:12 mikededo

Close in favor of https://github.com/sveltejs/eslint-plugin-svelte/pull/933

baseballyama avatar Dec 31 '24 08:12 baseballyama