Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(dead-code): exempt tool-loaded config, rc and startup-hook files (#2700)
Swati Ahuja67b87b711cf3
diff --git a/packages/core/src/repowise/core/analysis/dead_code/constants.py b/packages/core/src/repowise/core/analysis/dead_code/constants.pyindex aabc0629c..44dd2cded 100644--- a/packages/core/src/repowise/core/analysis/dead_code/constants.py+++ b/packages/core/src/repowise/core/analysis/dead_code/constants.py@@ -27,6 +27,9 @@ _DEAD_CODE_EXEMPT_LANGUAGES: frozenset[str] = (_NON_CODE_LANGUAGES | _LANG_REGISTRY.dead_code_exempt_languages())+# Extensions a JS tool's config file may take.+_JS_TOOL_EXTS: tuple[str, ...] = (".js", ".cjs", ".mjs", ".ts", ".cts", ".mts")+# Patterns that should never be flagged as dead. ``fnmatch`` ``*`` spans ``/``,# so a leading ``*`` matches nested and repo-root paths alike._NEVER_FLAG_PATTERNS: tuple[str, ...] = (@@ -52,12 +55,21 @@ _NEVER_FLAG_PATTERNS: tuple[str, ...] = ("*.d.ts","*setup.py","*setup.cfg",- "*next.config.*",- "*vite.config.*",- "*tailwind.config.*",- "*postcss.config.*",- "*jest.config.*",- "*vitest.config.*",+ # JS tooling loads its config by file name: ``<tool>.config.<ext>`` (and+ # variants like ``jest.config.base.js``), ``.<tool>rc.<ext>`` and pnpm's+ # install hook. fnmatch ``*`` spans ``/``, so an ``*rc.<ext>`` file under a+ # dot-directory is exempt too; an accepted recall loss.+ *(f"*.config{ext}" for ext in _JS_TOOL_EXTS),+ *(f"*.config.*{ext}" for ext in _JS_TOOL_EXTS),+ *(f".*rc{ext}" for ext in _JS_TOOL_EXTS),+ *(f"*/.*rc{ext}" for ext in _JS_TOOL_EXTS),+ ".pnpmfile.cjs",+ "*/.pnpmfile.cjs",+ # CPython imports these at startup when they sit on ``sys.path``.+ "sitecustomize.py",+ "*/sitecustomize.py",+ "usercustomize.py",+ "*/usercustomize.py",# Next.js / Remix / SvelteKit framework route files — loaded by the# framework at runtime, never imported via module imports."*/page.tsx",@@ -576,17 +588,10 @@ _NEVER_FLAG_PATTERNS: tuple[str, ...] = ("*.bench.tsx","*.bench.js","*.bench.mjs",- # Vitest / Playwright / Cypress config and workspace files.+ # Vitest workspace and shim files."*vitest.workspace.*","*vitest.shims.*","*vitest.root.*",- "*playwright.config.*",- "*cypress.config.*",- "*rollup.config.*",- "*esbuild.config.*",- "*tsup.config.*",- "*.config.mts",- "*.config.cts",# Codegen / generated artifacts."*.gen.ts","*.gen.tsx",@@ -603,6 +608,9 @@ _NEVER_FLAG_PATTERNS: tuple[str, ...] = ("*/instrumentation-client.ts","*/middleware.ts","*/middleware.js",+ # Next.js 16 renamed ``middleware`` to ``proxy``.+ "*/proxy.ts",+ "*/proxy.js","*/global-error.tsx","*/global-error.ts","*/forbidden.tsx",@@ -624,6 +632,7 @@ _NEVER_FLAG_PATTERNS: tuple[str, ...] = (# app lives at root."instrumentation.ts","middleware.ts",+ "proxy.ts","sitemap.ts","robots.ts",# Remix root/entry files — invoked by the framework runtime.diff --git a/tests/unit/dead_code/test_convention_never_flag.py b/tests/unit/dead_code/test_convention_never_flag.pynew file mode 100644index 000000000..7920b74b7--- /dev/null+++ b/tests/unit/dead_code/test_convention_never_flag.py@@ -0,0 +1,80 @@+"""Tool-loaded files that no import reaches are never reported unreachable.++Each convention has positives (loaded by a tool or runtime by name) and near+misses that must stay flaggable.+"""++from __future__ import annotations++import networkx as nx+import pytest++from repowise.core.analysis.dead_code.constants import never_flag_match+from repowise.core.analysis.dead_code.file_reachability import is_file_reachable+++def _unreachable(path: str) -> bool:+ graph = nx.DiGraph()+ graph.add_node(path, language="typescript")+ return not is_file_reachable(path, graph)+++ "path",+ [+ # Any tool's ``<name>.config.<js-family ext>`` is loaded by that tool.+ "webpack.config.js",+ "apps/docs/astro.config.mjs",+ "packages/ui/tsup.config.ts",+ "svelte.config.cjs",+ "packages/app/vite.config.mts",+ "drizzle.config.ts",+ # ``.<tool>rc.<js-family ext>``.+ ".eslintrc.js",+ "packages/web/.eslintrc.cjs",+ ".prettierrc.mjs",+ ".mocharc.ts",+ # pnpm's install hook.+ ".pnpmfile.cjs",+ "tools/.pnpmfile.cjs",+ # Next.js request proxy, the successor of ``middleware.ts``.+ "proxy.ts",+ "apps/web/proxy.ts",+ "apps/web/src/proxy.js",+ ],+)+def test_js_tool_convention_files_are_never_flagged(path):+ assert never_flag_match(path)+ assert not _unreachable(path)+++ "path",+ [+ # CPython imports these at startup when they are on sys.path.+ "sitecustomize.py",+ "src/sitecustomize.py",+ "usercustomize.py",+ "tools/usercustomize.py",+ ],+)+def test_python_startup_hooks_are_never_flagged(path):+ assert never_flag_match(path)+++ "path",+ [+ "src/config.ts", # no tool name before ``.config``+ "src/settings.config.py", # not a JS-family config+ "src/myconfig.js",+ "src/eslintrc.js", # not a dotfile+ "src/source.js", # ends in ``rc.js`` but is no rc file+ "src/api/reverse-proxy.ts",+ "src/httpproxy.ts",+ "src/mysitecustomize.py",+ "src/sitecustomize_helpers.py",+ ],+)+def test_near_misses_stay_flaggable(path):+ assert not never_flag_match(path)diff --git a/tests/unit/ingestion/test_manifest_entry_points.py b/tests/unit/ingestion/test_manifest_entry_points.pyindex a98ac354f..d79594328 100644--- a/tests/unit/ingestion/test_manifest_entry_points.py+++ b/tests/unit/ingestion/test_manifest_entry_points.py@@ -17,6 +17,7 @@ from types import SimpleNamespaceimport pytest+from repowise.core.analysis.dead_code.file_reachability import is_file_reachablefrom repowise.core.analysis.kg_curation import curate_knowledge_graphfrom repowise.core.analysis.knowledge_graph import build_knowledge_graph_skeletonfrom repowise.core.ingestion.graph import GraphBuilder@@ -246,3 +247,18 @@ def test_committed_declaration_target_is_not_an_entry() -> None:data = {"main": "./types/index.d.ts", "bin": "./types/cli.d.cts"}path_set = {"types/index.d.ts", "types/cli.d.cts"}assert manifest_entry_paths(".", data, path_set) == set()+++def test_bin_source_is_reachable_for_dead_code(tmp_path: Path) -> None:+ """A ``bin`` built from source keeps that source alive; a stray file does not."""+ repo = _write(+ tmp_path,+ {+ "package.json": json.dumps({"name": "tool", "bin": {"tool": "./dist/cli.js"}}),+ "src/cli.ts": "console.log('hi');\n",+ "src/old.ts": "export const unused = 1;\n",+ },+ )+ idx = _index(repo)+ assert is_file_reachable("src/cli.ts", idx.graph)+ assert not is_file_reachable("src/old.ts", idx.graph)