Skip to content

fix(ingestion): rescue local Express route middleware from unused-export detection#386

Open
joptimus wants to merge 1 commit into
repowise-dev:mainfrom
joptimus:fix/express-local-middleware-reads
Open

fix(ingestion): rescue local Express route middleware from unused-export detection#386
joptimus wants to merge 1 commit into
repowise-dev:mainfrom
joptimus:fix/express-local-middleware-reads

Conversation

@joptimus
Copy link
Copy Markdown
Contributor

@joptimus joptimus commented Jun 5, 2026

Summary

  • Detect Express route registrations on express()/Router()-initialised receivers and emit a reads edge from the file's ::__module__ symbol to each same-file middleware function passed by bare name, so local route middleware is no longer reported as an unused export.
  • Source the edge from ::__module__ (not the file node) to avoid clobbering the existing file→symbol defines edge in the single-edge DiGraph; a balanced-paren scan handles multiline calls and middleware factories before the handler, and string literals are stripped so route paths aren't mistaken for identifiers.
  • Keeps the fix narrow to Express: imported middleware (already rescued by import edges) and non-express()/Router() receivers (e.g. cache.get(fn)) are left untouched.

Related Issues

Fixes #373

Test Plan

  • Tests pass (pytest) — tests/unit/ingestion/test_express_framework_edges.py (11 passed); tests/unit/analysis tests/unit/dead_code tests/unit/ingestion + TS/CommonJS dead-code integration (1303 passed, 2 xfailed)
  • Lint passes (ruff check .)
  • Web build passes (npm run build) (no frontend changes)

New coverage: route-method reads edges, app.use middleware, defines-edge preservation, nested middleware-factory args, the .js/CommonJS multiline router.post(...) shape from #373, non-route receivers in an Express file, non-Express files gated out, and a dead-code regression proving the middleware exports are no longer flagged.

Checklist

  • My code follows the project's code style
  • I have added tests for new functionality
  • All existing tests still pass
  • I have updated documentation if needed (no docs impact)

…ort detection

Same-file middleware passed by bare name to a route registration
(router.post("/x", logRequest, handler)) is never seen by the import
graph, so the exports were flagged as dead. Detect route registrations on
express()/Router()-initialised receivers and emit a reads edge from the
file's ::__module__ symbol to each local-function argument, sourced there
to avoid clobbering the file->symbol defines edge in the single-edge graph.
A balanced-paren scan handles multiline calls and middleware factories
before the handler; string literals are stripped so route paths can't be
mistaken for identifiers.
@repowise-bot
Copy link
Copy Markdown

repowise-bot Bot commented Jun 5, 2026

✅ Health: 7.0 (unchanged)
2 files moved · 2 hotspots

⚠️ Change risk: moderate (riskier than 48% of this repo's commits · raw 8.6/10)
This change's risk is driven by:

  • large diff (many lines added)
File Score Δ Why
.../framework_edges/express.py 6.6 → 5.6 ▼ -0.9 🔻 introduced nested complexity, complex method · ✅ resolved dry violation
.../ingestion/test_express_framework_edges.py 9.7 → 9.3 ▼ -0.3 🔻 introduced duplicated assertion block · ✅ resolved dry violation

💡 .../framework_edges/express.py: Flatten the control flow. Pull early-return guards to the top, extract the deepest branch into a helper, and consider replacing nested conditionals with a strategy table or dispatch dict.

🔥 Hotspots touched (2)
  • .../framework_edges/express.py — 2 commits/90d, 1 dependents · primary owner: Swati Ahuja (96%)
  • .../ingestion/test_express_framework_edges.py — 1 commits/90d, 0 dependents · primary owner: Raghav Chamadiya (100%)

📊 Full report · ⭐ Star Repowise · 📥 Install bot · Last updated 2026-06-05 20:51 UTC
Silence on a single PR with [skip repowise] in the title · Per-repo toggle on repowise.dev/settings?tab=bot

@joptimus joptimus force-pushed the fix/express-local-middleware-reads branch from cbb7805 to 104c882 Compare June 5, 2026 20:51
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.

[Bug] Express route middleware identifiers can be reported as unused exports

1 participant