fix(scanner): stop dead-code flagging public API; deepen detection (Codex #10)#18
Merged
Merged
Conversation
…odex #10) The dead-code scanner flagged any export with no in-repo references as dead. But a package's public API lives in its entry point (index.* / __init__.py) and is consumed by code OUTSIDE the repo, where the usage grep is blind — so the whole API surface was reported as removable. That's the "shallow analysis" weakness Codex #10 called out. - Skip symbols declared in entry-point / barrel files. New optional `DeadCodeProfile.isEntryPoint(path)`; when a profile omits it the scanner applies a convention default (`index.ts|tsx|mjs|…` and `__init__.py`) via the exported `isEntryPointFile()` helper. - Make the uncertainty explicit: dead-code task descriptions now state the finding is grep-based reachability (not type-aware) and to confirm the symbol isn't reflectively used or part of an external API before removing. - Recall fix: the TS export regex now also matches `enum`, `abstract class`, and `async function` declarations (previously missed → silent gaps). Adds tests: entry-point exports are never flagged, non-entry unused exports are still flagged (now with the heuristic caveat), and an `isEntryPointFile` classification table. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Codex review finding #10 — dead-code analysis too shallow. The scanner flagged any export with no in-repo references as dead. But a package's public API lives in its entry point (
index.*/__init__.py) and is consumed by code outside the repo, where the usage grep is blind — so the entire public API surface was reported as removable. Acting on those findings would break downstream consumers.Changes
DeadCodeProfile.isEntryPoint(path); when a profile omits it, the scanner applies a convention default (index.ts|tsx|js|mjs|cjs|…and__init__.py) via the exportedisEntryPointFile()helper.severity: low.enum,abstract class, andasync functiondeclarations (previously silently missed).Why not full type-graph analysis
True reachability needs a TS type graph (ts-morph /
tsc --noUnusedLocalssemantics) — a heavy dependency and slow per-scan. This keeps the detector deterministic and fast while removing its single biggest false-positive class (public API) and making the residual uncertainty explicit to whoever acts on the task.Test plan
New
scanner.test.tscases:index.tswith no in-repo uses are not flaggedisEntryPointFiletable (index.* and__init__.pytrue;indexer.ts,my_init.py, plain source false)Local validation:
asil-improvement-loop191 tests, build + typecheck clean.