-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
fix: use arrow functions over bound funcs #12915
base: main
Are you sure you want to change the base?
fix: use arrow functions over bound funcs #12915
Conversation
Enable the [ESLint `@typescript-eslint/unbound-method-error` rule][1] and fix/ignore all the errors it throws at us. Basically, this rule warns us from unbinding a function (e.g. doing `const {x} = {x() { /* etc */}}` that doesn't explicitly have `this: void`. I've replaced these types with arrow functions when possible, to avoid users of the SvelteKit library from facing the same ESLint issues. I've also manually fixed some types in `packages/kit/src/exports/public.d.ts` that weren't caught by the `@typescript-eslint/unbound-method-error` rule, since they're only destructured in `packages/kit/test/apps`, which is ignored by our ESLint config. However, this manual change should fix sveltejs#12622. [1]: https://typescript-eslint.io/rules/unbound-method/ Fix: sveltejs#12622
🦋 Changeset detectedLatest commit: ec8dedc 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 |
Co-authored-by: Tee Ming <[email protected]>
|
Does this actually fix any bugs? It mostly looks like busy work to me |
I think it will close sveltejs/svelte#13481 and #12622 |
I see. So this would primarily help people who want to use that eslint rule in their own projects. I think what I might prefer to do is accept the changes to update the type definitions, but remove the enforcement and eslint ignore comments. One the pattern is in place, we'll follow it to be consistent, but I'd rather not litter the code with eslint ignores if we're not also avoiding bugs in the SvelteKit code |
Yep! It's part of the
Sounds good to me!
Although, every
This ESLint rule could help prevent bugs, but most of these invalid scope bugs would probably be caught in SvelteKit's tests, so it's probably not needed. |
I've made a separate PR that just modifes the public types and doesn't enable the ESLint Once it's merged, we can either decide to:
|
Enable the ESLint
@typescript-eslint/unbound-method-error
rule and fix/ignore all the errors it throws at us.Basically, this rule warns us from unbinding a function (e.g. doing
const {x} = {x() { /* etc */}}
that doesn't explicitly havethis: void
.I've replaced these types with arrow functions when possible, to avoid users of the SvelteKit library from facing the same ESLint issues.
There are some instances where ESLint throws an error when we are purposely doing this (e.g. we'd later call
func.apply(originalThis,
orfunc.call(originalThis,
, but since they're rare, I've just added// eslint-disable-next-line @typescript-eslint/unbound-method -- We'll pass `xxxxx` as `this`
comments there to ignore the error.kit/packages/kit/src/runtime/client/client.js
Lines 91 to 95 in b84e4dc
I've also manually fixed some types in
packages/kit/src/exports/public.d.ts
that weren't caught by the@typescript-eslint/unbound-method-error
rule, since they're only destructured inpackages/kit/test/apps
, which is ignored by our ESLint config. However, this manual change should fix #12622.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
parent
in load functions receive@typescript-eslint/unbound-method
error #12622 for me, but since the@typescript-eslint/*
rules ignorepackages/kit/test/apps/**
, it's possible that I've missed some issues.Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.packages/package
should be internal only, so we don't need to make a changeset for it.Edits