Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bfanger
Copy link

@bfanger bfanger commented Jul 6, 2024

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.

Copy link

changeset-bot bot commented Jul 6, 2024

🦋 Changeset detected

Latest commit: 5c29c5c

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

@ota-meshi
Copy link
Member

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

@ota-meshi ota-meshi marked this pull request as draft July 6, 2024 11:57
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.

2 participants