Check JSON response for knip to avoid false positives#7465
Merged
Conversation
alfonso-noriega
approved these changes
May 5, 2026
Contributor
Author
Merge activity
|
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.
WHY are these changes introduced?
The
Knip (unused code check)job can pass silently in CI even when knip never actually analyzes the codebase. We hit this in PR #7463: the job exited 0 with no output and was reported as green, even though runningpnpm kniplocally on the exact same SHA reproducibly fails with two unused dependencies. A false-green knip job lets real findings slip intomain.WHAT is this pull request doing?
bin/run-knip-ci.js, a small Node script that runs knip with--reporter jsonand validates the output before trusting the exit code.--reporter jsonalways emits a structured object on success ({"files":[],"issues":[]}), so an empty / unparseable stdout is a reliable signal that knip didn't actually run — in which case the script fails the job with a::error::annotation.Run knipstep in.github/workflows/tests-pr.ymlto a single line:node bin/run-knip-ci.js.How to test your changes?
I verified all three relevant scenarios locally against the real workspace:
main):node bin/run-knip-ci.jsexits 0 with no output.@graphql-typed-document-node/corefromknip.workspaces["packages/app"].ignoreDependenciesinpackage.json→ script re-runs knip in default reporter mode, printsUnused dependencies (1) ..., and exits 1.scripts.knipwithnode -e ""sopnpm knipexits 0 with empty stdout → script prints::error::knip exited N but produced no parseable JSON output. Failing CI to avoid a false green.and exits 1.You can reproduce 2 and 3 by editing
package.jsonas described above, runningnode bin/run-knip-ci.js, and reverting the edit.Checklist
pnpm changeset add