-
-
Notifications
You must be signed in to change notification settings - Fork 386
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Prerequisites
- I'm using the latest version
- I've read the relevant documentation
- I've searched for existing issues
- I've checked the list of known issues
- I've read the issue reproduction guide
Reproduction url
https://github.com/Jym77/knip-namespace
Reproduction access
- I've made sure the reproduction is publicly accessible
Description of the issue
Following up on #1603 (thanks for handling it).
(CodeSandbox seems to be having trouble with the knip repro setup (something about oxc-parser), and CodeBlitz somehow takes forever to (not) start, so I made a separate repo for repro instead).
index.ts:
import { foo, Bar } from "./foo.js"
namespace Foo {
export type Value = number // not used
export function foo(): number { // not used
return 1
}
}foo.ts:
export const foo = 1 // imported by index.ts
export const baz = 2
function bar(): Bar.Value { // unused, but not exported
return Bar.bar()
}
export namespace Bar { // imported by index.ts
export type Value = number // used by (top-level) bar
export function bar(): number { // used by (top-level) bar
return 1
}
}
export namespace Baz { // not used at all
export type Value = number // not used
export function baz(): number { // not used
return 1
}
}
namespace Qux { // not used, but local only
export type Value = number // not used
export function qux(): number { // not used
return 1
}
}knip output:
Unused exports (2)
baz src/foo.ts:2:14
Baz namespace src/foo.ts:16:18
Unused exported namespace members (2)
Value Bar src/foo.ts:9:15
bar Bar src/foo.ts:11:19
bazis correctly reported.Bar.ValueandBar.barare both incorrectly reported. They need to be exported for (top-level)barto access them.Bazis correctly reported as a single entity, it makes sense to not delve into it at this point.- Neither
Qux.ValuenorQux.quxare reported, despite none of them being used anywhere. Same goes forFoo.ValueandFoo.foo(who are in anentryfile, not just aprojectone).
So, it seems that knip detects the Bar usage from index.ts, therefore looks into it in details, but only from the index.ts point of view, thus not seing that its components are used from inside foo.ts and do need to be exported for that.
Of course, the most annoying part is the false positive reporting on Bar.Value and Bar.bar since it breaks CI/CD validation for incorrect reasons…
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working