Skip to content

Report unused re-exports when ignoreExportsUsedInFile is set#1895

Merged
webpro merged 3 commits into
webpro-nl:mainfrom
mlm20:fix-reexports-ignore-exports-used-in-file
Jul 21, 2026
Merged

Report unused re-exports when ignoreExportsUsedInFile is set#1895
webpro merged 3 commits into
webpro-nl:mainfrom
mlm20:fix-reexports-ignore-exports-used-in-file

Conversation

@mlm20

@mlm20 mlm20 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #1894

With ignoreExportsUsedInFile set, re-exports were always treated as used in their own file and never reported. A re-export like export type { Dead } from './schemas' has no local binding, so it cannot actually be used in its own file. When the source export was unused, --fix removed the export keyword at the declaration but left the re-export behind, and the project no longer compiled.

This removes the blanket isReExport check, so re-exports get the same local reference check as other exports. The import { X } plus export { X } case keeps working, since usage of X in the file is picked up by that check (covered by the existing re-export fixture).

The expected count in test/re-exports/ignore-exports-used-in-file.test.ts goes from 1 to 2: the unused export is now also reported at the re-export site, same as without ignoreExportsUsedInFile. That test was added for #698 to make sure the export is reported at all, so this stays in line with its intent.

@webpro

webpro commented Jul 20, 2026

Copy link
Copy Markdown
Member

The item.isReExport that's removed here was some kind of safety net. Removing it opens the door for certain false positives/negatives. So I'm trying to fix that up in my latest commit, can you please confirm it still behaves as expected?

@mlm20

mlm20 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Yep I can confirm that it work. Ran my original repro against d648f41, both Dead sites get reported now and --fix cleans up both. Thanks for tightening this!

@pkg-pr-new

pkg-pr-new Bot commented Jul 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/knip@1895
npm i https://pkg.pr.new/@knip/language-server@1895
npm i https://pkg.pr.new/@knip/mcp@1895

commit: d648f41

@webpro

webpro commented Jul 21, 2026

Copy link
Copy Markdown
Member

Thanks! These are real findings now: https://github.com/webpro-nl/knip/actions/runs/29754772364/job/88631556813?pr=1895

@webpro
webpro merged commit a113a5f into webpro-nl:main Jul 21, 2026
@webpro

webpro commented Jul 22, 2026

Copy link
Copy Markdown
Member

🚀 This pull request is included in v6.28.0. See Release 6.28.0 for release notes.

Using Knip in a commercial project? Please consider becoming a sponsor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 --fix strips source export but leaves re-export when ignoreExportsUsedInFile is set

2 participants