-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Problem
When a symbol is re-exported through a barrel file (index.ts), the dead_code detector considers the originating file as "alive" because it is re-exported by an entry point. However, the re-exported symbol itself may never be imported by any consumer.
This means symbols that are only used in tests but re-exported through barrel files are invisible to both:
dead_codedetector (file is re-exported → not dead)count_test_imports: falseoption (file-level check bypassed by re-export)
Example
packages/utils/src/
index.ts ← entry point, barrel: export * from './payload-sanitizer.js'
payload-sanitizer.ts ← exports sanitizePayload()
payload-sanitizer.spec.ts ← only consumer of sanitizePayload()
sanitizePayload is never imported by any production code, only by the test file. But the dead_code detector sees that payload-sanitizer.ts is re-exported through index.ts (an entry point) and considers it alive.
Current Behavior
dead_codedetector works at file levelis_reexported()returnstruebecauseindex.tsre-exportspayload-sanitizer.ts- File is not flagged, even though no consumer ever imports
sanitizePayloadfrom the barrel
Expected Behavior
The dead symbol detector (dead_symbols) should trace re-exports through barrel files and verify that the re-exported symbol is actually imported by at least one consumer downstream. If no consumer imports the symbol (only tests do), it should be flagged.
Possible Approaches
- Enhance
dead_symbolsdetector — when a symbol is re-exported through a barrel, check if any file imports that symbol from the barrel (not just that the barrel re-exports it) - Transitive usage analysis — follow re-export chains and verify end-to-end usage
- Combine with
count_test_imports— if the only downstream consumers are test files, flag the symbol
Related
- Dead code detector should flag code used only in tests #35 —
count_test_importsoption (file-level, doesn't cover barrel re-exports)