feat: dead code detector for Python codebases (#94) #181

Closed
Rockachopa wants to merge 0 commits from feat/94-dead-code-detector into main
Owner

Closes #94

Changes

Added scripts/dead_code_detector.py — AST-based analysis to find defined but never-called functions and classes.

How It Works

  1. Collect definitions: Scans all .py files for function/class/async definitions
  2. Collect usage: Tracks all name references, calls, imports across the repo
  3. Cross-reference: Any definition not referenced anywhere is flagged
  4. Exclude safe patterns: __init__, test_*, main, conftest, __init__.py exports

Output Format

file:line  type      name
─────────────────────────────────
scripts/foo.py  42  function  unused_helper
scripts/bar.py  18  class     DeprecatedWidget

Usage

# Text report
python3 scripts/dead_code_detector.py /path/to/repo/

# JSON output
python3 scripts/dead_code_detector.py /path/to/repo/ --format json

# With git blame
python3 scripts/dead_code_detector.py /path/to/repo/ --git-blame

# Exclude directories
python3 scripts/dead_code_detector.py /path/to/repo/ --exclude venv,tests,build
Closes #94 ## Changes Added `scripts/dead_code_detector.py` — AST-based analysis to find defined but never-called functions and classes. ## How It Works 1. **Collect definitions**: Scans all .py files for function/class/async definitions 2. **Collect usage**: Tracks all name references, calls, imports across the repo 3. **Cross-reference**: Any definition not referenced anywhere is flagged 4. **Exclude safe patterns**: `__init__`, `test_*`, `main`, `conftest`, `__init__.py` exports ## Output Format ``` file:line type name ───────────────────────────────── scripts/foo.py 42 function unused_helper scripts/bar.py 18 class DeprecatedWidget ``` ## Usage ```bash # Text report python3 scripts/dead_code_detector.py /path/to/repo/ # JSON output python3 scripts/dead_code_detector.py /path/to/repo/ --format json # With git blame python3 scripts/dead_code_detector.py /path/to/repo/ --git-blame # Exclude directories python3 scripts/dead_code_detector.py /path/to/repo/ --exclude venv,tests,build ```
Rockachopa added 1 commit 2026-04-15 03:46:46 +00:00
Timmy approved these changes 2026-04-15 04:13:18 +00:00
Timmy left a comment
Owner

Feature implementation reviewed - looks solid.

Scope: 1 file(s) changed (282+ / 0-)

Suggestions

  • Consider using specific exception types instead of bare except: clauses.
  • Feature PR without tests. Consider adding test coverage.
  • Found 10 print/console.log statements - verify these are not leftover debugging.
Feature implementation reviewed - looks solid. **Scope**: 1 file(s) changed (282+ / 0-) ### Suggestions - Consider using specific exception types instead of bare `except:` clauses. - Feature PR without tests. Consider adding test coverage. - Found 10 print/console.log statements - verify these are not leftover debugging.
Author
Owner

Closing as this PR cannot be merged (branch protection or conflicts). Please reopen if needed.

Closing as this PR cannot be merged (branch protection or conflicts). Please reopen if needed.
Rockachopa closed this pull request 2026-04-16 01:44:47 +00:00
Author
Owner

Closing: unmergeable due to conflicts or branch protection. Reopen if needed.

Closing: unmergeable due to conflicts or branch protection. Reopen if needed.
Author
Owner

Closing: unmergeable due to conflicts or branch protection. Reopen if needed.

Closing: unmergeable due to conflicts or branch protection. Reopen if needed.
Author
Owner

Closing: unmergeable due to conflicts or branch protection. Reopen if needed.

Closing: unmergeable due to conflicts or branch protection. Reopen if needed.
Rockachopa reopened this pull request 2026-04-16 02:03:57 +00:00
Rockachopa closed this pull request 2026-04-16 02:14:19 +00:00
Rockachopa reopened this pull request 2026-04-16 02:42:04 +00:00
Rockachopa closed this pull request 2026-04-16 02:52:38 +00:00

Pull request closed

Sign in to join this conversation.