Repository navigation
chore(tooling): report dead code with knip (#1356) - #1367
Merged
Merged
Conversation
Add knip 6.45.1 as a pinned development dependency, a knip.json scoped to the main process, src/, harnesses/, workers/ and scripts/ (public/ is excluded: renderer files share globals through script tags), a `task deadcode` command and a non-blocking `deadcode` job in the test workflow. The report comes first; removals and making the job blocking follow in separate PRs.
This was referenced Nov 29, 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.
Summary
First step of #1356: dead-code detection with knip, report only. Nothing is
removed and nothing blocks; removals and the blocking switch come in later PRs.
knip6.45.1 pinned exactly indevDependencies;package-lock.jsonregenerated with
npx npm@10 install --package-lock-only.knip.jsonat the root, scoped to the main process.task deadcoderuns the locked knip (npx --no-install knip, arguments after--pass through).deadcodejob in.github/workflows/test.yml: Node 22 onubuntu-latest,npm ci --ignore-scripts, knip's markdown report to the logand the job summary. The step has
continue-on-error: true, so the job staysgreen. Nothing
needsit, and it must not be added to the required checks.knip version
6.45.1 (published 2026-11-11) is the newest release at least 14 days old on
2026-11-29. 6.46.0 and later are under 14 days old. Engines:
^20.19.0 || >=22.12.0,so it supports Node 20 and 22; the job runs on Node 22 only. The lock adds 58
packages, all from knip's tree (
oxc-parser/oxc-resolverand theirper-platform bindings,
@emnapi/*,formatly,smol-toml,unbash, ...). Itremoves none. Two shared packages move up a minor version to meet knip's ranges,
and both stay inside their other dependents' ranges:
jiti2.6.1 -> 2.7.0(
app-builder-libwants^2.4.2) andtinyglobby0.2.15 -> 0.2.17 (node-gypwants
^0.2.12). npm also sorteddevDependenciesalphabetically, which movesmermaidabovepng2icons.Config choices
!):main.js(the packagemain, which knip detectsitself),
preload.jsandworkers/*.js. Workers are started withnew Worker(path.join(__dirname, 'workers', ...)), so they are listed bypattern.
scripts/*.{js,cjs}. Every script is run bypackage.json,Taskfile.yaml, a workflow, a test or by hand from a doc, or is required byone that is. Also
test/**/*.test.jsande2e/**/*.spec.js.*.js,src/**,harnesses/**(shipped by electron-builder),workers/**,scripts/**.public/**is ignored.kept alive by its unit test is not dead code.
task deadcode -- --productionshows what only tests keep alive (380 exports). It is not run in CI.
ignoreDependencies: the packages only the renderer loads (the five xtermaddons and
dompurifyfrompublic/index.html,codemirrorbundled frompublic/codemirror-setup.js). Also three packages tests reach on purposewithout listing them:
css-tree, resolved through jsdom's own path, andapp-builder-lib/builder-util, for electron-builder's macro helpers intest/build-workflow.test.js.path.join) are entries.require(path.join(worktree, 'node_modules', 'electron'))inscripts/test-pr.jsloads a package, not a local file. Tests that readmodules as source (for example
test/atomic-write-callers.test.js) only readfiles that are also required normally, so no extra entry or ignore was needed.
Report triage (default mode, the CI job's report)
--productioncss-treex2,app-builder-lib,builder-util)const ns = require('./x'); ns.name,const { name } = ns, ormodule.exports = { ...ns }intest/fixtures/trigger-watcher.cjs. One more (rewriteJsonlAtomic) is reached through a test that loads the module as source. Also measured on 6.49.0 with a three-file probe. Not fixable by config.The 55 include names that collide with unrelated locals elsewhere (for example
DEFAULT_DEBOUNCE_MS,SESSION_ID_RE,asEditorText, whichpublic/viewer-panel.jsdefines again). Two ambiguous.namematches turnedout unrelated:
actions.refusalis a factory result, andw.PERMISSION_MODESis a renderer stub. Before any removal PR, check each reported export for the
namespace pattern;
docs/development.mdsays so.Docs
docs/development.md, which addstask deadcodeto the command tableand a "Dead-code report" section (entries, project, ignores, production mode,
the known false positive), and
knip.jsonto itscovers..ai/contexts/build-release.md, which describes thedeadcodejob(one cell, install without scripts,
continue-on-error, not required) andadds it to the job and timeout lists.
Changelog
no-changelog: tooling only, users see nothing.Tests
test/deadcode-report.test.jsfailed before the Taskfile andworkflow changes (
not ok 3 ... 'task deadcode exists',not ok 4 ... 'test.yml has a deadcode job'), then passed 4/4.^6.45.1;public/**/*.jsadded toproject;checkdepending ondeadcode;continue-on-errorremoved;npm ciwithout--ignore-scripts.--test --test-concurrency=1 --test-timeout=120000, one at atime, all exit 0:
deadcode-report4/4,build-workflow17/17,check-changelog21 (2 skipped),check-doc-refs16/16,check-docs99/99,check-fast17/17,test-pr298/298,viewer-mermaid83/83.node scripts/check-docs.js --validate,node scripts/check-doc-refs.js(0 failures),
npx --no-install eslint test/deadcode-report.test.js,git diff --cached --check,SKIP_TESTS=1 task check:fast: all exit 0.npx --yes knip@6.45.1from the npx cache, about 11 s.Not verified:
deadcodejob itself has not run yet; this PR's CI is its first run.task deadcodelocally: knip is not installed in this checkout'snode_modulesyet, sonpx --no-install kniprefuses (by design) untilnpm install.knipas an unlisted binary (inTaskfile.yamland
test.yml) because it is not installed here. Afternpm cithat findingshould go away; this has not been measured.
task checksuite was not run.