Skip to content

ci: add dead code detection with knip, ts-prune, and ts-unused-exports#13801

Draft
DeJeune wants to merge 1 commit intomainfrom
DeJeune/deadcode-detection
Draft

ci: add dead code detection with knip, ts-prune, and ts-unused-exports#13801
DeJeune wants to merge 1 commit intomainfrom
DeJeune/deadcode-detection

Conversation

@DeJeune
Copy link
Copy Markdown
Collaborator

@DeJeune DeJeune commented Mar 26, 2026

What this PR does

Before this PR:
No automated dead code detection in CI. Unused files, exports, and dependencies accumulate silently.

After this PR:
Three dead code detection tools run as a parallel CI job on code changes:

  • knip — detects unused files, dependencies, and exports
  • ts-prune (via pnpm dlx) — detects unused TypeScript exports
  • ts-unused-exports (via pnpm dlx) — detects unused exports across tsconfig projects

All three tools run in strict/error mode — CI fails if any dead code is detected.

Why we need it and why it was done in this way

The following tradeoffs were made:

  • ts-prune and ts-unused-exports use pnpm dlx to avoid adding devDependencies; knip is installed because it needs a typed config file
  • knip config includes ignoreDependencies for false positives: dynamic imports (@cherrystudio/embedjs-loader-*), build plugins (@swc/plugin-styled-components, @electron/notarize), peer deps (TipTap collaboration, tailwindcss, etc.)
  • The deadcode-check CI job runs in parallel with existing jobs, gated by the same changes filter (main/renderer/shared)

The following alternatives were considered:

  • Single tool only — each tool catches different categories, using all three gives broader coverage
  • Warning-only mode — rejected in favor of strict enforcement to prevent dead code accumulation

Breaking changes

None

Special notes for your reviewer

  • All three tools run in error mode: CI will fail if dead code is detected
  • knip config ignores ambient .d.ts files, test fixtures, scripts, and dynamically-imported peer dependencies to reduce false positives
  • Existing dead code needs to be cleaned up before this CI check passes

Checklist

  • PR: The PR description is expressive enough and will help future contributors
  • Code: Write code that humans can understand and Keep it simple
  • Refactor: You have left the code cleaner than you found it (Boy Scout Rule)
  • Upgrade: Impact of this change on upgrade flows was considered and addressed if required
  • Documentation: A user-guide update was considered and is present (link) or not required.
  • Self-review: I have reviewed my own code before requesting review from others

Release note

NONE

- Add knip config with proper entry points and ignore patterns for
  false positives (ambient .d.ts files, dynamic imports, peer deps)
- Use pnpm dlx for ts-prune and ts-unused-exports (no devDependency)
- Add parallel deadcode-check job to CI, triggered on code changes
- Remove knip, ts-prune, ts-unused-exports from devDependencies

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: suyao <sy20010504@gmail.com>
@DeJeune DeJeune requested a review from EurFelux March 26, 2026 03:34
@EurFelux
Copy link
Copy Markdown
Collaborator

EurFelux commented Mar 26, 2026

Note

This comment was translated by Claude.

In #13531, I previously used knip and found some false positives. However, I didn't examine the configuration closely but rather had cc verify them individually. For automation, the configuration needs to be confirmed again.


Original Content

#13531 之前用 knip 发现会有一些误报,不过我没仔细看配置,而是让cc去逐个验证了。要自动化的话,需要再确认下配置

@EurFelux EurFelux linked an issue Mar 26, 2026 that may be closed by this pull request
4 tasks
@DeJeune DeJeune marked this pull request as draft March 26, 2026 14:53
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.

[Other]: Remove 28 confirmed dead code files identified by knip analysis

2 participants