Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(express): don't key mounts on callee name of call expressions (#4571)

EL Mehdi EL Mouatea552d6712448
diff --git a/packages/core/src/repowise/core/workspace/extractors/http/express.py b/packages/core/src/repowise/core/workspace/extractors/http/express.py
index 810bb8d5a..1f08ba4f8 100644
--- a/packages/core/src/repowise/core/workspace/extractors/http/express.py
+++ b/packages/core/src/repowise/core/workspace/extractors/http/express.py
@@ -41,7 +41,10 @@ if TYPE_CHECKING:
from ..base import ScanContext
# app.use('/prefix', router) — a cross-file (or in-file) router mount.
-_APP_USE_RE = re.compile(r"""\.use\s*\(\s*['"]([^'"]+)['"]\s*,\s*([\w.]+)""")
+_APP_USE_RE = re.compile(
+ r"""\.use\s*\(\s*['"]([^'"]+)['"]\s*,\s*"""
+ r"""([\w.]+?)(?:\.routes\s*\(\s*\)|(?![\w.]|\s*\())"""
+)
class ExpressDialect:
diff --git a/tests/unit/workspace/test_express_mount_key.py b/tests/unit/workspace/test_express_mount_key.py
new file mode 100644
index 000000000..4ef5ae24c
--- /dev/null
+++ b/tests/unit/workspace/test_express_mount_key.py
@@ -0,0 +1,22 @@
+import pytest
+
+from repowise.core.workspace.extractors.http.express import _APP_USE_RE
+
+
+def _key(src):
+ m = _APP_USE_RE.search(src)
+ return m.group(2).split(".")[-1] if m else None
+
+
+ "src, expected",
+ [
+ ('app.use("/api", require("./r"));', None),
+ ('router.use("/v1", child.routes());', "child"),
+ ('app.use("/users", users.router);', "router"),
+ ('app.use("/p", router);', "router"),
+ ('app.use("/p", a.b);', "b"),
+ ],
+)
+def test_express_mount_key(src, expected):
+ assert _key(src) == expected