cowork: namespace & side-effect imports consume a module's whole export surface - #49
Draft
Coding-Dev-Tools wants to merge 10 commits into
Draft
cowork: namespace & side-effect imports consume a module's whole export surface#49Coding-Dev-Tools wants to merge 10 commits into
Coding-Dev-Tools wants to merge 10 commits into
Conversation
…s Revenue Holdings / stale 2026 year); W-directed fleet-wide pass
…d-code scan
Named (`export { X } from './mod'`), renamed (`export { X as Y }`),
type (`export { type X }`), and star (`export * from './mod'`) re-exports
now mark the forwarded symbols as used, so barrel/index files no longer
produce false-positive 'unused_export' findings flagged removable=True
(which could delete live public API). Resolves `export *` specifiers to
scanned files (incl. directory index.*). Adds TestReexportForwarding
(8 cases) + removes a pre-existing F841 unused var. 113 tests pass, ruff clean.
… mixed default+named imports, and correct group-index reversal
- Rewrote _IMPORT_PATTERN regex to handle: import type {Foo}, import Default, {Named},
import {type Foo}, and import Foo as Bar forms
- Fixed _parse_imports group-number reversal (group 1 = named imports block, group 2 = default)
- Strips 'type ' prefix from named import entries in both named-block positions
- All 113 existing tests pass; ruff clean
…code # Conflicts: # CHANGELOG.md # src/deadcode/scanner.py # tests/test_scanner.py
…fect imports as whole-module consumption A namespace binding (import * as Utils from './utils') or a bare side-effect import (import './polyfill') consumes the target module's entire export surface. The scanner previously ignored both forms entirely, so exports used ONLY through them were falsely reported as unused with removable=True — live code queued for deletion by 'deadcode remove'. Both now resolve like barrel star-reexports: the resolved module's exports are treated as used. Bare package specifiers stay unresolvable and keep flagging. +5 regression tests (namespace, export * as ns, side-effect, bare-specifier, no-consumer control). Full suite: 121 passed, ruff clean.
The previous commit (2ef1848) was built from a stale temp index and accidentally recorded deletions of 34 unrelated tracked files. This commit restores the full tree of 30e09bb while keeping the intended scanner fix (namespace/side-effect imports as whole-module consumption) and its 5 regression tests. No force-push used.
…heckout-index efa7ce2 restored the tree but its checkout-index step reverted src/deadcode/scanner.py to the pre-fix version. This commit re-applies the scanner fix from 2ef1848: import * as NS / bare side-effect imports consume the target module's whole export surface (resolves like barrel star-reexports). Final tree vs master-base 30e09bb = exactly scanner.py fix + 5-test file.
🤖 Automated Code Review✅ Ruff Lint — No issues
|
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.
Problem
The dead-code scanner ignored two common import forms entirely:
import * as Utils from './utils'(namespace import)import './polyfill'(bare side-effect import)Exports consumed only through these forms were falsely reported as
unused_exportwithremovable=True— meaningdeadcode removewould blank live code. Reproduced pre-fix: a module whose only consumer usedUtils.helper()was flagged removable.Fix
Both forms now resolve their module specifier like barrel star-reexports already do (
_resolve_relative_module): when the target resolves to a scanned file, its entire export surface is treated as used. Bare package specifiers (e.g.'lodash') stay unresolvable and keep flagging local modules correctly.Tests
New
tests/test_namespace_sideeffect_imports.py(5 cases):export * as ns from ...re-export dittoFull suite: 121 passed, ruff clean.