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
7.04k stars 174 forks source link

detect unused fields returned by setup function #750

Closed neelance closed 3 months ago

neelance commented 3 months ago

Consider the following setup function:

const setupFoo = () => {
  // ...
  return {
    answer: 42,
    wrongAnswer: 43,
    doSomething: () => {
      // ...
    },
    // ...
  } as const;
}

We use this style a lot instead of classes, primarily with Vue components but also for other purposes. However, it happens quite often that someone adds a new field to the return value but later it becomes unused. It would be awesome if knip could detect such unused fields of object literals in a return statement.

webpro commented 3 months ago

Sorry, this is currently out of scope for Knip. We're not doing object members, let alone those in return statements.