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(health): ignore Rust local use paths in I/O imports (#2896)

Emre K.44b8bd454e4c
diff --git a/packages/core/src/repowise/core/analysis/health/perf/io_boundaries.py b/packages/core/src/repowise/core/analysis/health/perf/io_boundaries.py
index 55b6f49ec..87f956a26 100644
--- a/packages/core/src/repowise/core/analysis/health/perf/io_boundaries.py
+++ b/packages/core/src/repowise/core/analysis/health/perf/io_boundaries.py
@@ -50,6 +50,7 @@ _IMPORT_KW: frozenset[str] = frozenset(
"static",
}
)
+_RUST_LOCAL_ROOTS: frozenset[str] = frozenset({"crate", "self", "super"})
class _NodeLike(Protocol):
@@ -66,6 +67,17 @@ def _decode(node: _NodeLike) -> str:
return (node.text or b"").decode("utf-8", "replace")
+def _rust_scoped_candidate_parts(seg: str) -> list[str]:
+ """Classifiable parts of a Rust-style ``::`` path segment."""
+ parts = [c for c in seg.split("::") if c]
+ if parts and parts[0] in _RUST_LOCAL_ROOTS:
+ # Rust local paths can contain names like ``request`` / ``http`` /
+ # ``fs`` without importing the cross-ecosystem I/O libraries those
+ # bare segments usually identify.
+ return []
+ return parts
+
+
def _candidate_variants(tok: str) -> set[str]:
"""Every name a single import token could classify under.
@@ -88,7 +100,7 @@ def _candidate_variants(tok: str) -> set[str]:
# ``use sqlx::Pool`` resolves via ``sqlx`` and ``use std::fs`` via the
# ``fs`` segment (already a filesystem name, cross-ecosystem). A no-op
# for the dotted/slash ecosystems (no ``::`` to split).
- colon_parts = [c for c in seg.split("::") if c]
+ colon_parts = _rust_scoped_candidate_parts(seg)
out.update(colon_parts)
for i in range(1, len(colon_parts) + 1):
out.add("::".join(colon_parts[:i]))
diff --git a/tests/unit/health/test_perf_io_in_loop.py b/tests/unit/health/test_perf_io_in_loop.py
index fb815aa40..a6dc9b004 100644
--- a/tests/unit/health/test_perf_io_in_loop.py
+++ b/tests/unit/health/test_perf_io_in_loop.py
@@ -23,6 +23,7 @@ from repowise.core.analysis.health.biomarkers.string_concat_in_loop import (
StringConcatInLoopDetector,
)
from repowise.core.analysis.health.complexity import PerfHit, walk_file
+from repowise.core.analysis.health.perf.io_boundaries import collect_io_names
from repowise.core.analysis.health.scoring import score_file
_FIXTURE_DIR = Path(__file__).resolve().parents[2] / "fixtures" / "lang_samples"
@@ -367,6 +368,27 @@ def test_a_use_block_naming_two_io_modules_takes_the_first(use_block, expected):
assert set(fc.io_boundary_names.values()) == {expected}
+class _FakeImportNode:
+ def __init__(self, node_type: str, text: bytes, children: list[_FakeImportNode] | None = None):
+ self.type = node_type
+ self.text = text
+ self.children = children or []
+
+
+def test_rust_local_use_paths_are_not_io_boundaries():
+ root = _FakeImportNode(
+ "source_file",
+ b"",
+ [
+ _FakeImportNode("use_declaration", b"use crate::request::Foo;"),
+ _FakeImportNode("use_declaration", b"use super::http::fetch;"),
+ _FakeImportNode("use_declaration", b"use self::fs::helper;"),
+ ],
+ )
+
+ assert collect_io_names(root, "rust") == {}
+
+
def test_typescript_fixture_counts():
fc = _walk("typescript/perf_io_in_loop.ts", "typescript")
counts = _kinds(fc.perf_hits)