Skip to content

feat(vba): dead-code report with Access/VBA-aware exclusions - #349

Merged
ardelperal merged 5 commits into
mainfrom
feat/vba-dead-code
Nov 30, 2026
Merged

ardelperal merged 5 commits into
mainfrom
feat/vba-dead-code

Conversation

@ardelperal

@ardelperal ardelperal commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

Closes #344.

New command codegraph-vba dead-code [path] [--json] [--limit N]. It is built on upstream's buildDeadCodeReport (which had no CLI; only the viewer used it), with a VBA layer on top.

VBA rules

  • Not dead:
    • event procedures: event-handler edges, <Control>_<Event>, Form_/Report_ events, Class_Initialize/Terminate, WithEvents handlers taken from the graph;
    • Implements members;
    • Dysflow test modules (Test_*.bas, TestHelper.bas; not TESTAMENTO.bas).
  • Public procedures of standard modules, including those with no modifier (public by default), go to a separate "public, possibly external" list, because a macro or Application.Run may call them.
  • VBA-aware mention check. It ignores case, comments (including ' … _ continuation and Rem after :), the procedure's own body (a Function assigns its own name) and the CodeBehindForm copy when a .cls exists. It searches every VBA file to catch late-bound calls, using one identifier index per report with its own read budget, about 3× faster.
  • An unreadable file is reported with its reason and never hides the report silently.

Evidence on AGEDYS (163-file Access corpus)

85 dead and 77 public, possibly external (on current main, with #345/#346 merged):

  • A whole-corpus check of every listed name found no false positive.
  • 10 random dead rows and 10 random exclusions were checked by grep.
  • 372 event procedures are correctly excluded.
  • No graph edge changes.

21 tests on a minimal Access fixture, RED→GREEN. tsc is clean, and the VBA and dead-code subsets pass (84 files, 1337 tests). Native review approved after two follow-up rounds; the first spot-check caught an upstream rule that hid almost every VBA Function.

Follow-up

#350.

Adds `codegraph-vba dead-code [path] [--json] [--limit]` on top of
upstream's buildDeadCodeReport, with a VBA layer:
- event procedures (event-handler edges, <Control>_<Event>, Form_/Report_
  events, Class_Initialize/Terminate, WithEvents handlers) are not dead
- Implements members and Dysflow test modules (Test_*.bas) are excluded
- public procedures of standard modules go to a separate "public,
  possibly external" list (a macro or Application.Run may call them)
- the mention check is VBA-aware: case-insensitive, ignores comments, the
  procedure's own body (a Function assigns its own name) and the
  CodeBehindForm copy, and searches every VBA file for late-bound calls

On a 163-file Access corpus it reports 84 dead procedures and 77 public
ones, with no edge changed.

Closes #344
Review follow-ups: an unreadable VBA file is reported as a warning
(unreadableVbaFiles) instead of emptying the dead list; --limit accepts
only whole numbers of 1 or more; the summary describes the VBA mention
rule; the per-row VBA outcome is explicit; test-module names are matched
case-insensitively at a word boundary; CLI tests skip on a stale build.

Refs #344
Second-review follow-ups:
- the VBA mention text is read once per report with its own budget, so
  it never uses up the shared per-row file cap; skipped files are listed
  with a reason in vba.unreadableFiles
- one identifier index per report replaces the per-row rescan of every
  VBA file (about 3x faster on a 163-file Access corpus, same rows)
- comment blanking follows ' _' line continuation and Rem after ':'
- WithEvents handlers are recognised from graph facts, not source reads
- TESTAMENTO.bas is not a test module; Test_*.bas and TestHelper.bas are
- CodeBehindForm code is kept as mention text when the form has no .cls
- docs state the tested contract for unreadable files; CLI tests fail
  instead of skipping when CI is set

Refs #344
@ardelperal
ardelperal merged commit 408d676 into main Nov 30, 2026
5 checks passed
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.

feat(vba): dead-code report with Access/VBA-aware exclusions

1 participant