eslint consistent-return
error after migration to SvelteKit v2 (redirect, error)
#11467
-
Now that export const actions = {
deleteAccount: async ({ locals }) => {
const user = await authenticate(locals);
if (user) {
await prisma.user.delete({
where: { email: user.email },
});
return {};
}
redirect(303, '/');
},
} satisfies Actions;
How can this be resolved? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Putting a 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 |
Beta Was this translation helpful? Give feedback.
Putting a
return
in front ofredirect
works, but feels like a hacky workaround. You might argue it makes code more readable though, clearly showing that redirect exits the function:The only other option would be to disable the rule for that function:
// eslint-disable-next-line consistent-return