webpro-nl / knip

✂️ Find unused files, dependencies and exports in your JavaScript and TypeScript projects. Knip it before you ship it!
https://knip.dev
ISC License
6.52k stars 150 forks source link

Add support for Vue composables unused properties detection #756

Open maiolica opened 1 month ago

maiolica commented 1 month ago

A Vue composable is a function usually structured this way:

const useUserRole = (user: User) => {
  const isAdmin = computed(() => user.role === UsersRole.ADMIN);
  const isRegularUser = computed(() => user.role === UsersRole.REGULAR);

  return {
    isAdmin,
    isRegularUser,
  };
};

If isRegularUser is never exported in another file, ex.

const { isAdmin } = useUserRole();

could Knip detect it?

webpro commented 3 weeks ago

Knip currently can't detect it. Not members of exported objects, let alone those in return values.

A kind of similar request was unused props in React components.

Such features may one day be offered through custom "visitors" that may allow to implement what you need here (either optionally enabled in core or through external add-ons), but it's all very premature.