feat(prefer-let): add rule#985
Conversation
🦋 Changeset detectedLatest commit: ae7f479 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
commit: |
baseballyama
left a comment
There was a problem hiding this comment.
It's better to consider $bindable.
Could you explain a bit more in depth? Do you mean only to suggest using |
|
I personally prefer using let only when there is a bindable prop, and using const otherwise. It would be better if there are a configuration that allows let only when a bindable prop is present. While writing this, I also thought that prefer-const might need some related adjustments as well. |
|
I post more details about this. $stateUsers may want to define export const Time3 = () => {
// If `$state` has object value,
// Time3 user cn reassign `value.value` even without reassign logic in this composable.
// Therefore it can be declare as both `const` / `let`
const value = $state( { value: new Date().toString() });
return {
get value() {
return value;
}
}
}$propsThe use of
$derivedFor ConclusionGiven these considerations, this rule might be better named Detail code for each case is here. |
|
And for the |
|
@baseballyama I see what you mean. The original discussion started because rune values may not be reassigned in the code itself, but they are by Svelte underthehood: #818 (comment). While I'm more on the second view (to declare everything as At the same time, maybe it'd make more sense to have one rule, which would force either |
|
Duplicate of #806 or was my implementation missing something? The references from both $derived & $props are reassigned by Svelte.
So if we want one rule (or a default configuration), I suggest following the Javascript specification and use This is also the way all examples are written in the the Svelte documentation. |
|
I want to enforce const for props instead of let to maintain data flow integrity, even if the compiler reassigns values under the hood. (I am speaking with the assumption that I have a relatively good understanding of the Svelte 5 runtime.) |
No! Not really, just that it had not been updated for 7 months, and I thought I'd be a nice addition to the plugin. At the same time, I'm starting to prefer a rule that allows users to choose whether they prefer |
I agree with this, but I also understand those who prefer |
Yes. I think current |
|
We could make "svelte/prefer-const" configurable to enforce the described Where let: Show a linting error when using const for signals. Autofix to let |
|
I'd rather implement @baseballyama's proposal, as adding for instance, I may want We could re-write the |
|
@mikededo That should be the behavior of: rules: {
"svelte/prefer-const": { signals: "const" }
} |
|
Adding an option to |
|
In any case, it seems that there is a consensus regarding the requirements that should be implemented as rules. I think adding an option to the In that regard, it might be safer to limit changes to the |
Implements the
prefer-letrule.Closes #818.