Skip to content

Fix/knip files runtime safe#128

Open
acoBOYZ wants to merge 2 commits intomillionco:mainfrom
acoBOYZ:fix/knip-files-runtime-safe
Open

Fix/knip files runtime safe#128
acoBOYZ wants to merge 2 commits intomillionco:mainfrom
acoBOYZ:fix/knip-files-runtime-safe

Conversation

@acoBOYZ
Copy link
Copy Markdown

@acoBOYZ acoBOYZ commented Apr 14, 2026

This fixes a runtime crash in the Knip integration when issues.files is missing..

Previously, we directly iterated over issues.files, which could throw in edge cases when the field was unavailable at runtime.
Now we normalize it first with a runtime-safe fallback:

const fileIssues = issues.files ?? new Set();

Then we iterate over fileIssues instead of issues.files.

This keeps existing behavior unchanged when file issues are present, while preventing failures when Knip returns incomplete or variant output.

Tests I added

  • Added a regression test for missing issues.files in `runKnip
  • Confirmed normal behavior remains intact for valid issues.files values

Note

Low Risk
Low risk: small defensive change to avoid a runtime crash when Knip omits issues.files, plus a focused regression test.

Overview
Prevents runKnip from crashing when Knip returns issues.files as missing/undefined by normalizing it to an empty Set before iteration.

Adds a Vitest regression test that mocks Knip output without issues.files and asserts runKnip resolves to an empty diagnostics array.

Reviewed by Cursor Bugbot for commit d028dfd. Bugbot is set up for automated code reviews on this repo. Configure here.

acoBOYZ added 2 commits April 14, 2026 18:39
Handle missing knip file issues safely by defaulting to an empty Set and iterating that normalized collection.

Made-with: Cursor
Add a runKnip regression test that verifies missing issues.files does not throw and returns empty diagnostics.

Made-with: Cursor
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 14, 2026

@acoBOYZ is attempting to deploy a commit to the Million Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d028dfd. Configure here.

const diagnostics: Diagnostic[] = [];

for (const unusedFile of issues.files) {
for (const unusedFile of fileIssues) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing runtime safety for other issue record types

Medium Severity

The fix adds a nullish-coalescing fallback for issues.files but doesn't apply the same guard to issues.exports, issues.types, or issues.duplicates. These are passed directly to collectIssueRecords, which calls Object.values(records) — this throws a TypeError if any of those fields are undefined. If Knip can return incomplete output missing files, it can equally omit these other fields, causing the same runtime crash this PR aims to prevent.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d028dfd. Configure here.

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.

1 participant