Repository navigation
Check unused modules, exports and types with knip in pre-commit - #5055
Merged
Merged
Conversation
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
reviewed
Nov 2, 2026
leaf-agent
left a comment
Collaborator
There was a problem hiding this comment.
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.
leaf-agent
approved these changes
Nov 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.jslists the modules something other than an import loads (boot, the public package API, the suite'scheck-api.jswindows,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/throughtests/served-paths.mjs, the composition the runtime tests already use. Thekniphook (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:
version.jsexports onlysince-seen.jsreadKnip misses what only an entry's loader reads: an entry's exports all count as read, so an unused re-export on
check-api.jsor 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:
elementAxes(element-frame.js), lit'sclassMap,styleMapandunsafeHTML(framework.js),langForPath(syntax.js, sobrowser/AGENTS.md's owner index now nameslanguage-paths.js, which defines it), andnameAction,relabel,offerElement,selectableOffer,selectableOfferedandgenerated(widget-elements.js);exportontimeline-view.js'sclock;leaf-dev unused-exports, theimportsreading intests/js_facts.mjs, and its dev test.leaf.jsnow handspage-geometry.jsthe fivetarget-paint.jsfunctions 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.jsnotes 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.