Skip to content

svelte/prefer-svelte-reactivity triggers inside non-reactive functions (e.g., URL, Date, Set usage) #1271

@cnolte

Description

@cnolte

Version: [email protected]

The svelte/prefer-svelte-reactivity rule currently triggers even inside regular functions where Svelte's reactivity is not needed or doesn't make sense.

e.g.:

const getNextPage = () => {
  const newUrl = new URL(page.url) // !!! This leads to an error
  newUrl.pathname = page.url.pathname
  newUrl.searchParams.set('p', (pageNum + 1).toString())
  return newUrl.toString()
}

In this context:

  • new URL(...) is a straightforward operation.
  • There's no reactive dependency tracking needed.
  • Restructuring this logic into a reactive statement (e.g., using SvelteURL()) would be unnecessary.
  • I would also expect the reactive version to be slower than the native one.

I've encountered similar false positives with other built-ins like Date and Set.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions