Skip to content

chore: setup knip for dead code detection#2135

Merged
synoet merged 1 commit intomainfrom
synoet/knip
Mar 23, 2026
Merged

chore: setup knip for dead code detection#2135
synoet merged 1 commit intomainfrom
synoet/knip

Conversation

@synoet
Copy link
Copy Markdown
Contributor

@synoet synoet commented Mar 23, 2026

No description provided.

@synoet synoet requested a review from a team as a code owner March 23, 2026 22:31
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 23, 2026

Walkthrough

The changes introduce Knip dependency auditing tool integration. A new configuration file js/app/knip.ts is created with a KnipConfig default export that specifies ignore patterns for generated and vendored code, workspace configurations with explicit entry and project globs for multiple packages, and a list of dependencies to ignore during static analysis. The package.json file is updated to add Knip v6.0.4 as a dev dependency and include a new knip npm script using the Bun package manager runner.

Poem

🐰 Hop hop, the dependencies are clear!
With Knip's keen eye, no unused code here,
Configuration set with patterns so fine,
Workspaces aligned in a bunny-audit line! 🐇

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive No pull request description was provided by the author. Add a description explaining why knip is being set up, what it detects, and any relevant context or configuration details.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: setting up knip for dead code detection in 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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch synoet/knip

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

@github-actions
Copy link
Copy Markdown

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 `@js/app/knip.ts`:
- Around line 5-10: Remove the redundant exclusion of "packages/loro-mirror"
from the ignore array and rely only on the ignoreWorkspaces setting to skip that
workspace; specifically, delete the "packages/loro-mirror/**" entry from the
ignore array (the ignore array and the ignoreWorkspaces setting are both present
in js/app/knip.ts) so the workspace is only excluded via ignoreWorkspaces,
keeping configurations DRY.
- Around line 63-107: The current Knip config uses broad wildcards
('**/*.{ts,tsx}') for entry and project for packages like
'packages/block-canvas', 'packages/block-chat', 'packages/block-image',
'packages/block-md', 'packages/block-pdf', 'packages/block-project',
'packages/block-unknown', 'packages/block-video', 'packages/block-code',
'packages/block-channel', and 'packages/channel', which makes every file an
entry so Knip cannot detect unused exports; fix this by replacing the wildcard
entry/project for each package with the package's explicit entry point(s) (e.g.,
'src/index.ts' or whatever the package's public export file(s) are) and restrict
project to the package TS source/glob or its tsconfig (so entry lists actual
public entry files and project points to the package source/tsconfig), updating
the corresponding package entries in js/app/knip.ts to those specific
files/globs to restore dead-code detection.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 603c01d2-93bf-4510-a624-91f6158fee62

📥 Commits

Reviewing files that changed from the base of the PR and between 7bbe20a and 78f19fc.

⛔ Files ignored due to path filters (1)
  • js/app/bun.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • js/app/knip.ts
  • js/app/package.json

Comment on lines +5 to +10
ignore: [
'**/generated/**',
'scripts/**',
'packages/loro-mirror/**',
'packages/service-storage/**',
],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Consider consolidating packages/loro-mirror exclusion.

The packages/loro-mirror directory is excluded in both ignore (line 8) and ignoreWorkspaces (line 37). While this works, it's redundant:

  • ignore: Excludes files from analysis
  • ignoreWorkspaces: Excludes the workspace from workspace processing

If the intent is to completely skip this workspace, ignoreWorkspaces alone should suffice. Consider removing line 8 to reduce duplication.

♻️ Suggested simplification
   ignore: [
     '**/generated/**',
     'scripts/**',
-    'packages/loro-mirror/**',
     'packages/service-storage/**',
   ],

Also applies to: 36-37

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@js/app/knip.ts` around lines 5 - 10, Remove the redundant exclusion of
"packages/loro-mirror" from the ignore array and rely only on the
ignoreWorkspaces setting to skip that workspace; specifically, delete the
"packages/loro-mirror/**" entry from the ignore array (the ignore array and the
ignoreWorkspaces setting are both present in js/app/knip.ts) so the workspace is
only excluded via ignoreWorkspaces, keeping configurations DRY.

Comment on lines +63 to +107
// Block packages and others consumed via tsconfig path aliases (no index.ts entry)
'packages/block-canvas': {
entry: ['**/*.{ts,tsx}'],
project: ['**/*.{ts,tsx}'],
},
'packages/block-channel': {
entry: ['**/*.{ts,tsx}'],
project: ['**/*.{ts,tsx}'],
},
'packages/block-chat': {
entry: ['**/*.{ts,tsx}'],
project: ['**/*.{ts,tsx}'],
},
'packages/block-code': {
entry: ['**/*.{ts,tsx}'],
project: ['**/*.{ts,tsx}'],
},
'packages/block-image': {
entry: ['**/*.{ts,tsx}'],
project: ['**/*.{ts,tsx}'],
},
'packages/block-md': {
entry: ['**/*.{ts,tsx}'],
project: ['**/*.{ts,tsx}'],
},
'packages/block-pdf': {
entry: ['**/*.{ts,tsx}'],
project: ['**/*.{ts,tsx}'],
},
'packages/block-project': {
entry: ['**/*.{ts,tsx}'],
project: ['**/*.{ts,tsx}'],
},
'packages/block-unknown': {
entry: ['**/*.{ts,tsx}'],
project: ['**/*.{ts,tsx}'],
},
'packages/block-video': {
entry: ['**/*.{ts,tsx}'],
project: ['**/*.{ts,tsx}'],
},
'packages/channel': {
entry: ['**/*.{ts,tsx}'],
project: ['**/*.{ts,tsx}'],
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Using broad wildcard entries for block packages.

The block packages use **/*.{ts,tsx} as both entry and project, which effectively treats all files as entry points. While this may be intentional for packages consumed via tsconfig path aliases (as noted in the comment), it means Knip won't detect unused exports within these packages.

If these packages grow, consider defining more specific entry points to enable better dead code detection within each package.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@js/app/knip.ts` around lines 63 - 107, The current Knip config uses broad
wildcards ('**/*.{ts,tsx}') for entry and project for packages like
'packages/block-canvas', 'packages/block-chat', 'packages/block-image',
'packages/block-md', 'packages/block-pdf', 'packages/block-project',
'packages/block-unknown', 'packages/block-video', 'packages/block-code',
'packages/block-channel', and 'packages/channel', which makes every file an
entry so Knip cannot detect unused exports; fix this by replacing the wildcard
entry/project for each package with the package's explicit entry point(s) (e.g.,
'src/index.ts' or whatever the package's public export file(s) are) and restrict
project to the package TS source/glob or its tsconfig (so entry lists actual
public entry files and project points to the package source/tsconfig), updating
the corresponding package entries in js/app/knip.ts to those specific
files/globs to restore dead-code detection.

@synoet synoet merged commit e574b99 into main Mar 23, 2026
27 checks passed
@synoet synoet deleted the synoet/knip branch March 23, 2026 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant