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

Svelte 5 runes support #587

Open
benmccann opened this issue Sep 20, 2023 · 6 comments
Open

Svelte 5 runes support #587

benmccann opened this issue Sep 20, 2023 · 6 comments
Labels
enhancement New feature or request feat: svelte v5

Comments

@benmccann
Copy link
Member

Description

There's a few places it'd be helpful such as in linting the Svelte 5 repo and component party examples (matschik/component-party.dev#186)

I don't think there's any rush on this and the syntax may change, but I thought it'd be helpful to have a place to track it

@benmccann benmccann added the enhancement New feature or request label Sep 20, 2023
@ota-meshi
Copy link
Member

MEMO:

When using $derived, there seems to be a problem with TS inference, similar to the problem we had in the past.

sveltejs/svelte-eslint-parser#226

input:

<script lang="ts">
type EventInfo = {
  start_at: Date | number
}
let info: EventInfo | null = null

const lightFormat = (i: Date | number) => i.toString()

fetch('/fakeurl').then(() => { info = { start_at: 0 } }).catch(console.error)

const startDate = $derived(info?.start_at ? lightFormat(info.start_at) : null)
const endDate = () => (info?.start_at ? lightFormat(info.start_at) : null)
</script>
 
{startDate}{endDate}

error:

Unsafe assignment of an any value. (@typescript-eslint/no-unsafe-assignment)

Reproduce:

https://eslint-online-playground.netlify.app/#eNqlVF1v0zAU/SvGQlqL1pTnsG5I+xA8AA8gXuYJZc5t6s2xg+2UTSX/nXvtpO26UiH2VCfn3HOP77npinsnp58ez23dWAMmZH4JOgDP+YmXTjWB6cJUM8GDF/xUmPDYALtcIvOjmVs2YythGPOhcOFHEXJ2UQRgv5lp61twwnTCaAhMITffKiOC1lhNP8III63x2EpVi3BlXV0ExEZqR27MZqdMZcF+DU6ZajSmyjkEuRgdTefFPbROH42zsAAzGkXyKnYml1sW37KOdeNMFlRIja2GDJyzLgomK5Eeu8/Y6xKcWkI5IrGzbFBiZ9uGI7jGxiyPd0PFpAem7NWSs//TOpmmUDAIJsxqbbJb9fodP8aksOVcVdmdtwaDjAkJLjFipcF9aYJCS4LnKTvCPA5Uhs/Y5HwB8j6CwbVAeHec6pWRui2BoGuscFLwGwwYG9IKBZ8Fj82GeWpbjQT/AFrbV4KP3yEtA6+VCU7uGIOHgO5jz+vBUKLmDtB1jSiUgkcfBDa6rZTJ06ZOD3Le076mmU2S5kv4Ewc/W0W7NyHeRNKw8ElwkrnpBwVm+WS4t87+8vgx7Jlppe1toVMW+DgsGj0L7qAordGPgq/5TeFQaV+CIOviOziPQKrWuA0+bN3Q29ZJ+Ia+E6G2ZavxvCZgDq64whW5pEBIqc+E938KGPhmXs7egUR9knqycWkYg2O7xC9LlbAdb2+a4Dm2G7q8wQ1CO/iWTg/DUW7e1nQcPGzmkUzsiW6AU0GydKD97i13OyS8F58MyDPy83h2pbZeE0C3+qcbxFsMx/4Qf/oPsSnkfVHBzvdVwvICGlpgI1W67nptDrTcu0R7+MM44gf0l7LEOQj2ApMhhP07fAjcWHtKiOtIA+r+AMxHSic=

@benmccann
Copy link
Member Author

FYI @dummdidumm

@ota-meshi
Copy link
Member

Hmm... $derived can also be used in *.ts.
So probably just fixing svelte-eslint-parser won't solve it.

@lampewebdev
Copy link

Not sure if this is correct here but you can see that there is a problem here:

image

@dummdidumm
Copy link
Member

I think the quickest solution is to either add known globals to eslint so that it knows that $state/$derived etc exist, or to postprocess eslint errors related to "$state/$derived/etc doesn't exist" to surpress them if you're inside .svelte or .svelte.ts/js files.

@ota-meshi
Copy link
Member

ota-meshi commented Nov 22, 2023

We have started work on Svelte v5 support.
If you want to try it out, install the next tagged version and try it out.

npm i -D eslint-plugin-svelte@next

Additional configuration is required if you want to support for *.svelte.js and *.svelte.ts.
https://github.com/sveltejs/svelte-eslint-parser#runes-support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feat: svelte v5
Projects
None yet
Development

No branches or pull requests

4 participants