Skip to content

eslint consistent-return error after migration to SvelteKit v2 (redirect, error) #11467

Discussion options

You must be logged in to vote

Putting a return in front of redirect works, but feels like a hacky workaround. You might argue it makes code more readable though, clearly showing that redirect exits the function:

export const actions = {
  deleteAccount: async ({ locals }) => {
    const user = await authenticate(locals);
    if (user) {
      await prisma.user.delete({
        where: { email: user.email },
      });
      return {};
    }
    return redirect(303, '/');
  },
} satisfies Actions;

The only other option would be to disable the rule for that function:

// eslint-disable-next-line consistent-return

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@eltigerchino
Comment options

Answer selected by eltigerchino
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants