Skip to content

Check unused modules, exports and types with knip in pre-commit - #5055

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

@max-sixty max-sixty commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

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

The export check from #5028 counted an export 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.
Knip, configured with the modules something other than an import loads
and the served-path composition (tests/served-paths.mjs), finds those
twelve and nothing else, and also reports modules nothing loads. On the
tree before #5014 it found six of that change's eight and the three
version.js exports since-seen.js alone read, which the word check only
reached after the deletion. It misses what only an entry's loader reads,
such as an unused re-export on check-api.js.

The `knip` hook replaces `unused-exports`, and `leaf-dev unused-exports`,
js_facts.mjs's `imports` reading and its dev test go.

Removed: the re-exports of `elementAxes` (element-frame.js), lit's
`classMap`, `styleMap` and `unsafeHTML` (framework.js), `langForPath`
(syntax.js), and `nameAction`, `relabel`, `offerElement`,
`selectableOffer`, `selectableOffered` and `generated`
(widget-elements.js); `export` on timeline-view.js's `clock`.

leaf.js now hands page-geometry.js the five target-paint functions it
calls rather than the module namespace. Knip 6.44.1 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.
# Conflicts:
#	dist/kernel/kernel.json

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the langForPath re-export leaves the maintainer's owner index pointing at an API that no longer exists. In browser/AGENTS.md, the row “The language a file path means” still names syntax.js / langForPath. Point that row at language-paths.js, which owns the function, alongside removing the facade export.

Confirmed with uv run pytest tests/model/test_owner_index.py -q -n0: it fails with the question index names owners its modules don't export: ['syntax.js langForPath'].

syntax.js no longer re-exports langForPath, so the row names the module that
defines it; tests/model/test_owner_index.py failed on the stale owner.
@max-sixty
max-sixty merged commit 46e6d06 into main Nov 2, 2026
4 checks passed
@max-sixty
max-sixty deleted the dead-code-check branch November 2, 2026 05:09
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