Skip to content

Check unused JavaScript exports in pre-commit, beside vulture - #5028

Merged
max-sixty merged 5 commits into
mainfrom
dead-code-check
Nov 2, 2026
Merged

max-sixty merged 5 commits into
mainfrom
dead-code-check

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

The JavaScript export check (tests/journeys/test_unused_exports.py) ran only in the daily journeys tier. That run has failed every day this week, with over a hundred failures each time, so an orphaned export reached main and stayed until Tend triaged the daily report: #4724 and #4873 left seven on 30 and 31 October, and #5014 removed them on 1 November. Vulture, its Python counterpart, runs as a pre-commit hook, which both landing paths (a pull request's lint step and wt merge's pre-merge) run over the whole tree, so the change that orphans a Python definition is the one told.

This moves the export check beside vulture:

  • leaf-dev unused-exports holds the check, unchanged, with the test's docstring as its module header. It takes about two seconds.
  • .pre-commit-config.yaml runs it as unused-exports, woken locally by the file kinds that export or read (.js, .mjs, .ts, .py, .html, .md, worker/wrangler.toml). CI runs every hook on every file.

It also removes what #5014's deletion of since-seen.js left behind:

  • the keepalive option of deliverBookkeeping and postEvent, which only the departing seen send set, and runtime.seen, which only since-seen.js read;
  • the six arrival tests skipped while since-seen.js was unmounted. The module, renamed test_changes_in_place.py, keeps the comparison and at-work tests;
  • the prose in change-walk.js, events.md, read_state.py, agent_state.py and browser/AGENTS.md that described the turned-off marking. The server's reading of seen events is unchanged, and no tab posts one.

And it drops the uuid devDependency, which no module imports. A one-off knip scan of dependencies flagged 33; the other 32 are bundled from build/entries, loaded by evals or tests/*.mjs, or resolved as types and peers. As #2326 and #3423 found for exports, knip would need more configuration than it saves, so it is not added as a gate.

Validation: leaf-dev unused-exports and every pre-commit hook pass on the changed files; pnpm run check:browser, the 737 runtime tests, and the browser test for comparison bars and the h walk pass.

This was written by Claude Code on behalf of max-sixty

The export check was a test in the daily `journeys` tier, whose runs fail
every day with hundreds of failures, so its findings went unread: main
carried eight exports nothing reads, seven of them left by #4724 and
#4873. It now runs as `leaf-dev unused-exports`, a pre-commit hook beside
vulture, so a pull request's lint step and `wt merge` check the whole tree
on every change. The check itself is unchanged and takes about two seconds.

Seven of the eight lose `export`, since only their own module uses them:
`readDocumentHeaders`, `SHOT_VIEWS`, `outlineDocument`, `containedSpace`
and `selectableOfferElement` (also dropped from `widget-elements.js`),
and the re-exports of `runtimeRootState` from `check-api.js` and lit's
`Directive` from `framework.js`, whose one user imports lit directly.
A one-off knip scan of dependencies flagged 33; uuid is the one with no
reader anywhere in the tree. The others are bundled from build/entries,
loaded by evals or tests/*.mjs, or resolved as types and peers.
Marking what changed since the user last saw the page was turned off in
#4890 by commenting out its mount, which left `createSinceSeen` as the one
export the unused-exports check still reported. By the user's choice it is
deleted rather than kept parked; restoring it means restoring the module
from 792abf4 and its mount in `application.js`.

With it go what only it used: `version.js`'s `offerComparison`,
`stopComparison` and the `offered` path of `showComparison`; the
`keepalive` option of `deliverBookkeeping` and `postEvent`, which only
the departing `seen` send set; and `runtime.seen`. The six arrival tests
it skipped are deleted, and `test_since_seen.py` becomes
`test_changes_in_place.py` for the comparison and at-work tests that
remain. The server's reading of `seen` events is unchanged; no tab posts
one.
# Conflicts:
#	browser/runtime/application.js
#	browser/runtime/version.js
#	dist/kernel/kernel.json
#	dist/kernel/runtime/check-api.js
delivery.js's bookkeeping send is a third caller beside the gesture queue
and the error report.
@max-sixty
max-sixty merged commit 38f7f9b into main Nov 2, 2026
5 checks passed
@max-sixty
max-sixty deleted the dead-code-check branch November 2, 2026 00:07
max-sixty added a commit that referenced this pull request Nov 2, 2026
The export check from #5028 counted an export as read wherever a Python,
HTML or Markdown file named it as a word. The package references
document the public API by name, so every facade re-export of a public
name stayed alive: on main it reported nothing while twelve exports had
no reader. This replaces it with knip, run by pre-commit like vulture
and dependency-cruiser.

`knip.config.js` lists the modules something other than an import loads
(boot, the public package API, the suite's `check-api.js` windows,
`lf-*` widget modules, the render gate's probes, scripts the suite
injects, and the Node, Workers and harness programs), and resolves
`/runtime/`, `/vendor/` and `/widgets/` through
`tests/served-paths.mjs`, the composition the runtime tests already use.
The `knip` hook (knip 6.44.1, installed by pre-commit as
dependency-cruiser is) reports unused modules, exports and types, and
takes about ten seconds.

Measured on two trees:

| Tree | Word check | knip |
|---|---|---|
| main before this change | nothing | the twelve exports below, and five
false findings (see below) |
| main before #5014 | that change's eight | six of the eight, the
twelve, and the three `version.js` exports only `since-seen.js` read |

Knip misses what only an entry's loader reads: an entry's exports all
count as read, so an unused re-export on `check-api.js` or an unused
helper exported from a render-gate probe module goes unreported. Those
were the two of #5014's eight it missed.

Removed, as nothing reads them:

- the re-exports of `elementAxes` (`element-frame.js`), lit's
`classMap`, `styleMap` and `unsafeHTML` (`framework.js`), `langForPath`
(`syntax.js`, so `browser/AGENTS.md`'s owner index now names
`language-paths.js`, which defines it), and `nameAction`, `relabel`,
`offerElement`, `selectableOffer`, `selectableOffered` and `generated`
(`widget-elements.js`);
- `export` on `timeline-view.js`'s `clock`;
- `leaf-dev unused-exports`, the `imports` reading in
`tests/js_facts.mjs`, and its dev test.

`leaf.js` now hands `page-geometry.js` the five `target-paint.js`
functions it calls instead of the module namespace. Knip's documented
namespace-import heuristic (its guide, "Namespace Imports") credits a
namespace import that its module both reads members of and passes whole
with only the members read, so it reported those five as unused;
`knip.config.js` notes this.

Validation: the hook passes on the merged tree and fails on a planted
unused export, a re-export only prose names, and an orphan module; every
pre-commit hook, `pnpm run check:browser`, the 737 runtime tests and an
aim browser test pass.

> _This was written by Claude Code on behalf of max-sixty_
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.

2 participants