knip icon indicating copy to clipboard operation
knip copied to clipboard

False positive on method that is used in base class of base class

Open JoshuaKGoldberg opened this issue 2 years ago • 1 comments

👋 Reporting https://github.com/JoshuaKGoldberg/ts-api-utils/issues/343 over here. The relevant classes in https://github.com/JoshuaKGoldberg/ts-api-utils/blob/8c747294f24d0adca8817f4028832b855d907b5b/src/usage/scopes.ts are:

  1. abstract class AbstractScope implements Scope
  2. class NonRootScope extends AbstractScope
  3. class NamespaceScope extends NonRootScope

NamespaceScope defines a finish() method. That method is referenced in the AbstractScope class method end, in a this.namespaceScopes.forEach((value) => value.finish(cb));. Yet Knip is reporting it as unused:

$ pnpm lint:knip:production

> [email protected] lint:knip:production /Users/josh/repos/ts-api-utils
> knip --config knip.production.jsonc --production

Analyzing workspace ....
The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting
Unused exported class members (1)
finish  NamespaceScope  src/usage/scopes.ts:358:2
 ELIFECYCLE  Command failed with exit code 1.

JoshuaKGoldberg avatar Dec 24 '23 04:12 JoshuaKGoldberg

Very odd. In --production mode vitest is not imported (no test files included), and that's somehow what makes the difference in behavior.

You can drop import "vitest" in src/index.ts and it won't report finish as unused anymore.

webpro avatar Dec 27 '23 08:12 webpro