Skip to content

Add knip for dead code detection#311

Merged
brianmhunt merged 3 commits intomainfrom
modern-tooling/phase-5-knip
Apr 16, 2026
Merged

Add knip for dead code detection#311
brianmhunt merged 3 commits intomainfrom
modern-tooling/phase-5-knip

Conversation

@brianmhunt
Copy link
Copy Markdown
Member

@brianmhunt brianmhunt commented Apr 15, 2026

Summary

  • Add knip.json config with monorepo workspace awareness
  • Add bun run knip script
  • Remove unused fs-extra devDependency
  • No source code changes — findings addressed in Phase 6

Findings

Category Count
Unused files 3
Unused dependencies 8
Unlisted dependencies 10
Unused exports 10
Unused exported types 19
Duplicate exports 2

See plans/knip.md for full details.

Lesson from PR #234

The previous knip attempt mixed linter config with code changes (verbatimModuleSyntax, type refactoring, export cleanup) in a 56-file PR. This time: config only. Findings get fixed in focused follow-up PRs.

Test plan

  • bun run knip runs and reports known findings
  • bun run build succeeds
  • bunx vitest run — 2679 tests pass
  • No source code changes

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a new development script called knip to the project's available development commands.
  • Chores

    • Removed the fs-extra dependency from development dependencies as it was no longer needed.
    • Added new configuration and documentation files to support the new development tooling.
    • Updated the development workflow documentation to reference the newly available script command.

Copilot AI review requested due to automatic review settings April 15, 2026 19:22
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: decfad1ccb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread package.json Outdated
"lint": "bunx @biomejs/biome lint .",
"lint:fix": "bunx @biomejs/biome check --fix .",
"check": "bunx @biomejs/biome check .",
"knip": "bunx knip",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Pin knip in devDependencies

This adds "knip": "bunx knip" but does not add knip to devDependencies/bun.lock, so the command depends on Bun auto-install behavior instead of a repo-pinned tool version; Bun’s bunx docs note it falls back to installing from npm when not locally installed, which makes dead-code results non-reproducible across environments and can fail in restricted/offline CI runners. Please add a pinned knip devDependency so bun run knip resolves through the lockfile.

Useful? React with 👍 / 👎.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 15, 2026

Warning

Rate limit exceeded

@brianmhunt has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 45 minutes and 45 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 45 minutes and 45 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3fbcf3eb-91bb-49c5-86e2-a24a014d3391

📥 Commits

Reviewing files that changed from the base of the PR and between decfad1 and d372336.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • AGENTS.md
  • knip.json
  • package.json
  • plans/knip.md
📝 Walkthrough

Walkthrough

This PR introduces Knip, a dead-code detection tool, into the repository by adding configuration, npm scripts, and planning documentation. It establishes workspace-aware analysis through knip.json, adds a new npm/bun script command, removes an unused dependency (fs-extra), and documents the implementation roadmap.

Changes

Cohort / File(s) Summary
Documentation & Planning
AGENTS.md, plans/knip.md
Added knip build command to AGENTS.md workflow docs; created new plan documentation outlining knip implementation roadmap, findings categories, current phase scope, and verification steps.
Configuration
knip.json
New Knip configuration defining workspaces with per-workspace entry files and project globs, and ignoreDependencies list for excluded packages.
Package Configuration
package.json
Added knip script invoking bunx knip; removed fs-extra from devDependencies.

Possibly related PRs

Poem

🐰 A knip, a snap, no code left unused,
Dead branches trimmed, no longer confused,
From fs-extra's old grip we're released,
Config and scripts have peace increased! 🌿

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add knip for dead code detection' is clear, concise, and directly summarizes the main change—introducing knip as a dead-code detection tool into the repository.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch modern-tooling/phase-5-knip

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds initial Knip setup to the monorepo to enable dead-code/dependency detection, plus accompanying documentation and a small dependency cleanup.

Changes:

  • Add knip.json with workspace-aware entry/project globs.
  • Add a root bun run knip script.
  • Remove fs-extra from root devDependencies (and update bun.lock).

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
plans/knip.md Documents intent/phases and summarizes expected knip findings for follow-up work
package.json Adds knip script; removes fs-extra devDependency
knip.json Introduces initial knip workspace configuration and ignore list
bun.lock Lockfile updates reflecting the dependency graph after removing fs-extra
AGENTS.md Documents the new bun run knip command

Comment thread knip.json
},
"packages/*": {
"entry": ["index.ts", "src/index.ts"],
"project": ["src/**/*.ts"]
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

The knip workspace globs exclude the repo’s test files (e.g. packages/*/spec/**/*.ts), so dependencies/exports that are only referenced from tests can be reported as “unused” even though the test suite relies on them. Consider including spec/**/*.ts in the relevant workspaces’ entry and/or project patterns so knip’s findings better reflect actual codebase usage.

Suggested change
"project": ["src/**/*.ts"]
"project": ["src/**/*.ts", "spec/**/*.ts"]

Copilot uses AI. Check for mistakes.
Comment thread plans/knip.md
|---|---|---|
| Unused files | 3 | `builds/*/src/common.ts`, `tools/template/index.ts` |
| Unused dependencies | 8 | `@tko/*` packages not imported, declared in package.json |
| Unused devDependencies | 1 | `fs-extra` (leftover from old tooling) |
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

The findings table lists fs-extra as an unused devDependency, but this PR also removes fs-extra from root devDependencies. After the dependency removal, that particular finding should no longer apply—please update the table (and totals, if needed) to reflect the post-PR baseline knip output.

Suggested change
| Unused devDependencies | 1 | `fs-extra` (leftover from old tooling) |

Copilot uses AI. Check for mistakes.
Comment thread plans/knip.md
Comment on lines +27 to +30
1. Add `knip.json` config with workspace awareness
2. Add `bun run knip` script to package.json
3. Add knip to CI (warn-only, non-blocking initially)
4. Remove `fs-extra` from devDependencies (genuinely unused)
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

This plan/PR description says knip is added to CI (and later claims the CI workflow runs and reports findings), but this PR’s changes don’t include any .github/workflows/* updates and there are no existing workflow references to knip. Either add the CI workflow change in this PR or adjust the documentation/PR description so it matches what’s actually being shipped.

Copilot uses AI. Check for mistakes.
Comment thread package.json Outdated
"lint": "bunx @biomejs/biome lint .",
"lint:fix": "bunx @biomejs/biome check --fix .",
"check": "bunx @biomejs/biome check .",
"knip": "bunx knip",
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

bun run knip invokes bunx knip, but knip is not pinned in devDependencies. In this repo, other CLI tools are pinned in devDependencies even when run via bunx (e.g. @biomejs/biome, typescript, vitest in package.json:15-44), which keeps CI/results reproducible and avoids network-fetching arbitrary latest versions. Add knip to devDependencies (ideally matching the major used by the knip.json schema) and update bun.lock accordingly.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@package.json`:
- Line 20: Add a pinned devDependency for the Knip CLI so the "knip" npm script
(the "knip": "bunx knip" entry) uses a deterministic version instead of fetching
whatever bunx resolves at runtime; update package.json devDependencies to
include a specific knip version compatible with knip.json (e.g., "knip": "5.x"
or an exact "5.0.0") and run install so CI/local runs use that pinned CLI.

In `@plans/knip.md`:
- Around line 27-31: The plan text in plans/knip.md wrongly implies CI
integration is included in this PR and uses the non-standard command `bunx
knip`; update the wording to reflect the implemented scope (add knip config and
package script only) and standardize the command to `bun run knip` (and mention
adding a package.json script named e.g. "knip"); also change any statements that
say "Add knip to CI" to indicate it's planned or optional (warn-only) rather
than already added and apply the same fixes to the repeated lines referenced
(also at 42-45).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fbc76507-d3d2-4a17-aca7-cc6dc658b4a9

📥 Commits

Reviewing files that changed from the base of the PR and between d4aead2 and decfad1.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • AGENTS.md
  • knip.json
  • package.json
  • plans/knip.md

Comment thread package.json Outdated
Comment thread plans/knip.md
Brian M Hunt and others added 2 commits April 16, 2026 05:39
Configure knip with workspace awareness for the TKO monorepo.
Add `bun run knip` script. Remove unused fs-extra devDependency.

Findings (config only, no code changes):
- 3 unused files, 8 unused deps, 10 unlisted deps
- 10 unused exports, 19 unused exported types, 2 duplicate exports
These will be addressed in Phase 6 (separate PRs per category).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@brianmhunt brianmhunt force-pushed the modern-tooling/phase-5-knip branch from 706f3ec to e508e22 Compare April 16, 2026 09:40
Ensures version control, lockfile pinning, and minimumReleaseAge
protection. Script now runs `knip` directly instead of `bunx knip`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@brianmhunt brianmhunt merged commit 4536248 into main Apr 16, 2026
5 checks passed
@brianmhunt brianmhunt deleted the modern-tooling/phase-5-knip branch April 16, 2026 09:58
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