Skip to content

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

New issue

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

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

Already on GitHub? # to your account

Closed
wants to merge 1 commit into 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

@bfanger bfanger force-pushed the feature/prefer-const branch from 4f1a00a to 5c29c5c Compare July 6, 2024 11:54
@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
@mikededo
Copy link
Contributor

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

@baseballyama
Copy link
Member

Close in favor of #933

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants