-
-
Notifications
You must be signed in to change notification settings - Fork 47
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 no-unnecessary-state-wrap
rule
#1062
Conversation
4b97e52
to
219a5e5
Compare
🦋 Changeset detectedLatest commit: fe121fd 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 |
Try the Instant Preview in Online PlaygroundInstall the Instant Preview to Your Local
Published Instant Preview Packages:
|
49448ae
to
e4bbfe5
Compare
e4bbfe5
to
1640da2
Compare
Hi, |
Since the |
I still have to disagree - the rule now has a clear false positive that can be detected by its implementation, but just isn't. |
Can you provide an example of fp? |
Of course, see #1052 (comment) for a simple example or here for a real-world example (this one is in |
Then, let’s add an option to not report an error when a reassignment exists. |
Thanks :) I don't even think it needs to be an option - if a |
I don’t think so. I believe it might simply be a mistake. At least in my project, I want to consistently treat it as an error. For example, in the following case, it can clearly use “clear”. let map = $state(new SvelteMap());
map = new SvelteMap(); |
Hmm, you are absolutely right that the code snippet is incorrect, thanks, I din't realize that! I am thinking if this isn't a separate issue, though - the anti-pattern here is IMO assigning a Now if that were a separate rule it would nicely dovetail with this one even if this rule ignored all re-assigned variables, the other rule would replace the re-assignment with I feel I am rambling a little bit - do I make any sense to you? :D |
In any case, for those who don’t want this rule enabled, they can simply disable it. In most cases, |
I added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Overview
This PR introduces a new ESLint rule, svelte/no-unnecessary-state-wrap, to disallow redundant $state wrapping for reactive classes in Svelte. Key changes include:
- Implementation of the new rule in the plugin with appropriate configurations.
- Comprehensive test fixtures for basic errors, additional custom classes, reassign scenarios, and import alias handling.
- Updates to documentation, configuration files, and the rule types file to integrate the new rule.
Reviewed Changes
File | Description |
---|---|
docs/rules/no-unnecessary-state-wrap.md | Adds documentation for the new rule. |
packages/eslint-plugin-svelte/src/rules/no-unnecessary-state-wrap.ts | Implements the rule logic with suggestions for removal of unnecessary wrapping. |
packages/eslint-plugin-svelte/tests/fixtures/rules/no-unnecessary-state-wrap/* | Provides test fixtures covering various error scenarios. |
.changeset/popular-needles-remain.md | Updates the changeset with the feature. |
packages/eslint-plugin-svelte/src/rule-types.ts | Extends the rule types for the new rule. |
packages/eslint-plugin-svelte/src/configs/flat/recommended.ts, README.md, docs/rules.md, packages/eslint-plugin-svelte/src/utils/rules.ts | Updates configuration and documentation to include the new rule. |
Copilot reviewed 26 out of 26 changed files in this pull request and generated no comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks!
close: #1052