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

False positive in no-immutable-reactive-statements #484

Closed
2 tasks done
marekdedic opened this issue May 16, 2023 · 3 comments · Fixed by sveltejs/svelte-eslint-parser#337
Closed
2 tasks done

False positive in no-immutable-reactive-statements #484

marekdedic opened this issue May 16, 2023 · 3 comments · Fixed by sveltejs/svelte-eslint-parser#337
Labels
bug Something isn't working feat: typescript

Comments

@marekdedic
Copy link
Contributor

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.

What version of ESLint are you using?

8.40.0

What version of eslint-plugin-svelte are you using?

2.28.0

What did you do?

I am implementing a setup for loading images in pages (i.e. something like calling an API endpoint to get the first 15 images, then loading the next 15 for the next page and so on...). To do this, I am using 4 variables in this way:

<script>
  /* eslint svelte/no-immutable-reactive-statements: "error" */

  let page = 1;
  const perPage = 15;
  $: pageStart = perPage * (page - 1);
  $: pageEnd = pageStart + perPage;

  $: imagesOnThisPage = images.slice(pageStart, pageEnd);
</script>

{#each imagesOnThisPage as image}
 ... show the image
{/each}

<div
  on:click={() => {
    page += 1;
  }}
>
  Next page
</div>

What did you expect to happen?

I expected no issue, as both pageStart and pageEnd need to be reactive, otherwise paging won't work.

What actually happened?

I got svelte/no-immutable-reactive-statements error for pageStart (and also pageEnd if I make pageStart non-reactive)

Link to GitHub Repo with Minimal Reproducible Example

I think the example should be a repro as it is, let me know if it isn't :)

Additional comments

No response

@ota-meshi ota-meshi added the needs repro Need a repository that can reproduce the problem label May 16, 2023
@marekdedic
Copy link
Contributor Author

Whoa, this is really strange - see this playground

If I remove the Pagination element, the issue disappears - as it probably should. But what is really strange is that the issue also disappears if I remove the <div> or lang="ts" - what is happening here???

@ota-meshi
Copy link
Member

After investigating, it seems that the scope manager information returned by the parser differs depending on whether ts is used. I don't know the specific cause yet.

@ota-meshi ota-meshi added bug Something isn't working feat: typescript and removed needs repro Need a repository that can reproduce the problem labels May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feat: typescript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants