Fix import parsing: handle import type {Foo}, mixed default+named, fix group-index reversal#47
Fix import parsing: handle import type {Foo}, mixed default+named, fix group-index reversal#47Coding-Dev-Tools wants to merge 6 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
🤖 Automated Code Review✅ Ruff Lint — No issues
|
Coding-Dev-Tools
left a comment
There was a problem hiding this comment.
Pre-PR review (Pre-PR Code Analyzer) — VERDICT: BLOCK (merge prevented until fixed).
Broken package.json. The diff to package.json removes the MIT license value and leaves a dangling key:
- "license": "MIT",
- "author": "Coding-Dev-Tools",
- "license"
"repository": {
The new + "license" line has no : "MIT" value and no trailing comma, so the file is no longer valid JSON. npm install / npm publish and any tool parsing package.json will fail with a parse error. This is a merge blocker.
Fix: restore the license field with its value and comma, e.g. "license": "MIT",.
Minor: the LICENSE file now reads Copyright (c) 2025 while the rest of the repo uses 2026 — align the year.
The scanner.py import/reexport parsing changes (EXPORT_PATTERN default fix, EXPORT_LIST re-export exclusion, IMPORT_PATTERN rewrite, new REEXPORT_PATTERN, export-* resolution) are well-structured and address a real false-positive class. Once package.json is valid this is a solid dead-code false-positive fix.
Coding-Dev-Tools
left a comment
There was a problem hiding this comment.
Review Verdict: REQUEST_CHANGES (posted as COMMENT due to self-review embargo)
🔴 BLOCKER: package.json is invalid JSON (will break npm install/publish)
The diff shows a broken JSON object at lines 42-44:
"license"\n "repository": {The "license": "MIT" value and trailing comma were dropped, leaving a dangling key. This will cause npm install and npm publish to fail with a parse error.
Required fix: Restore the license field and comma:
"license": "MIT",
"repository": {✅ Strengths (logic + tests)
- Correct re-export handling: New
_REEXPORT_PATTERN+star_reexportstracking +_resolve_relative_moduleproperly marks barrel-forwarded symbols as used. Prevents false-positive "removable" findings on public API. - Import parsing upgrades: Handles
import type { Foo },import Default, { named },import { type Foo }— all covered by new tests (test_type_import_counts_as_used,test_mixed_default_and_named_import_counts_as_used, etc.). - Default-export exclusion: Deliberately skips
export defaultfrom removable candidates (correct — entry points). - Test coverage: 15 new tests in
TestReexportForwarding+ 5 import-type tests = strong regression guard.
⚠️ CI Gate Failure
ensure-pr job failed (likely sandbox gh auth). All test matrices pass (3.10–3.13). The package.json fix is mandatory before merge.
Fix: Import parsing in scanner
The regex-based import parser had two bugs causing silent-false-positives (imported names reported as unused):
Bug 1: Group-index reversal
The regex had group 1 = and group 2 = single , but the code treated group 1 as the default import and group 2 as named imports. Named-block content (e.g.
{ myFunc }) was stored as a literal import name with leading whitespace, somyFuncnever matched the stored key and was always reported as unused.Bug 2: Missing patterns
The regex only handled
import {Foo} from ...andimport Foo from .... Missing:import type {Foo} from ...(TypeScript type-only imports)import Default, {Named} from ...(mixed default + named)import {type Foo} from ...(inline type prefix)import Foo as Bar from ...(aliased default)Fix
_IMPORT_PATTERNregex with 4 capture groups (named block, default name, optional second named block, module specifier)_parse_importsto correctly assign names from all 3 name-bearing groupstypeprefix from named import entriesVerification