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

New Rule: svelte/kit-parent-function-at-bottom rule #438

Open
baseballyama opened this issue Apr 13, 2023 · 5 comments
Open

New Rule: svelte/kit-parent-function-at-bottom rule #438

baseballyama opened this issue Apr 13, 2023 · 5 comments
Labels
enhancement New feature or request new rule
Milestone

Comments

@baseballyama
Copy link
Member

Motivation

I would like to recognize performance overhead regarding parent.

/** @type {import('./$types').PageLoad} */
export async function load({ params, parent }) {
  const parentData = await parent();
  //                       ^ `parent` function can execute later to avoid a waterfall
  const data = await getData(params);

  return {
    ...data
    meta: { ...parentData.meta, ...data.meta }
  };
}

Description

SvelteKit has parent function. And according to the document, parent should use at the bottom of load function as much as possible in terms of performance.

https://kit.svelte.dev/docs/load#using-parent-data

But it's too difficult to recognize by human code review, so I would like to recognize this automatically.

Examples

/** @type {import('./$types').PageLoad} */
export async function load({ params, parent }) {
  // NG
  const parentData = await parent();
  const data = await getData(params);
  // OK
  const parentData = await parent();
  // OK (Because `doSomething` needs to use the return value of `parent`.)
  const foo = await doSomething(parentData);

  return {
    ...data
    meta: { ...parentData.meta, ...data.meta }
  };
}

Additional comments

I need to think about better rule name.😅

@baseballyama baseballyama added enhancement New feature or request new rule labels Apr 13, 2023
@ota-meshi
Copy link
Member

New rule sound good to me!
We need a better rule name, as you say, but I don't have any ideas 😓

@devunt
Copy link

devunt commented Apr 15, 2023

How about svelte/avoid-waterfall-in-kit-loads?

@ota-meshi
Copy link
Member

Hmm. I'm not familiar with English, so I'm not sure what "waterfall" means. So I'm not sure if that naming of the rule makes sense 😓. I would like someone's opinion on that name.

@baseballyama
Copy link
Member Author

waterfall is used in the kit doc. So this word itself is natural.

@baseballyama
Copy link
Member Author

But to protect waterfall, possibly we need to take care something more in the future, so I'd like to use a name that has a specific check purpose.
I mean "This is is just check the place of parent function. Not check everything regarding avoiding waterfall"

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

No branches or pull requests

3 participants