Repository navigation
chore(tooling): make the dead-code job blocking (#1356) - #1371
Merged
Merged
Conversation
The surplus exports are gone; what knip still reported were exports read through CommonJS namespace access, a spread re-export in a test fixture, a module loaded as source by its test, or module.exports read back by the module itself. Silence those per file and for unused exports only, and drop continue-on-error so a new finding fails the workflow.
A file-wide ignoreIssues entry also hid any new unused export in the same file. A knip preprocessor now drops exactly the listed (file, export) pairs, each with its reason, and lowers the counters knip derives its exit code from; a listed pair knip no longer reports fails the run so stale entries get removed.
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.
Summary
Last part of #1356. After #1369 removed the surplus exports, the 45 exports knip still reported are false positives. This change silences them in
knip.jsonand makes thedeadcodejob blocking:continue-on-erroris gone from the step, and the job sets none, so a new unused file, export or dependency now fails the workflow. The job still runs once, on Node 22 /ubuntu-latest, withnpm ci --ignore-scriptsand the locked knip (6.45.1).Whether
deadcodeis a required status check is a repository ruleset setting that only the maintainer can change. This PR does not change it.Allow-list mapping
scripts/knip-preprocessor.jsis thepreprocessorofknip.json(knip 6.45.1,run-cli.js: the preprocessor receives the report, and the exit code is computed from the counters it returns). It drops exactly the 45 (file, export) pairs of the part-2 KEEP rows, oneALLOWED_UNUSED_EXPORTSentry each with a reason, and decrementscounters.exportsandcounters.total. Any other unused export, in the same file or not, still fails knip. A listed pair knip no longer reports throws and fails the run, so stale entries get removed. NoignoreIssuesremains. It is wired through the config key, sotask deadcodeand the CI step pick it up unchanged; a--preprocessorflag would replace it, and the test refuses one.Reasons: namespace = CommonJS namespace access in app code, test-namespace = namespace access or destructuring in tests, fixture-spread = spread re-export in
test/fixtures/trigger-watcher.cjs, source-loaded = module loaded as source by its test, self-read = module readsmodule.exports.nameitself.archived-projects.jsjsonl-scan.jsproject-remap.jssession-transitions.jsworktree-delete.jssrc/main/changes/git-changes-file.jssrc/main/projects/project-delete-writer.jssrc/main/remote/remote-ssh-binary.jssrc/main/schedules/schedule-background.jssrc/main/schedules/schedule-delete-file.jssrc/main/schedules/schedule-ipc.jssrc/main/schedules/schedule-run-results.jssrc/main/session-index/read-counters.jssrc/main/triggers/trigger-name.jssrc/main/triggers/trigger-watcher.jsMeasured locally with
npx --yes knip@6.45.1 --exclude binaries: exit 0 with the preprocessor. An unused export appended tojsonl-scan.js, one of the listed files, is reported (jsonl-scan.js: knipProbe) and knip exits 1 (reverted). A fake stale entry makes knip fail withjsonl-scan.js#goneExportnamed (reverted).Docs
docs/development.md: the CI paragraph and "Dead-code report" now say the job fails on any finding. They name the false-positive patterns and describe the preprocessor allow-list. They say how to handle a new false positive: add one (file, export, reason) entry and give in the PR the line that reads the export, never a file-wideignoreIssues, a glob or a global switch. They also note thattask deadcode -- --preprocessor …replaces the allow-list for that run..ai/contexts/build-release.md: thedeadcodeparagraph describes a blocking job with nocontinue-on-error, the per-pair preprocessor, what the two tests check, and that required-check status is a ruleset setting.Taskfile.yaml: thedeadcodedescription no longer says "report only".Tests
test/knip-preprocessor.test.js(new, 8 tests): every entry is one posix file, one identifier, a known reason, no duplicate. The listed pairs are dropped and an unlisted export in the same file is kept, withcounters.exportsandtotalmatching. A listed symbol in another file is kept. Other issue types are untouched. A listed pair knip no longer reports rejects, naming the pair. A run that does not report exports is passed through. Backslash keys match. Red first against an identity stub: 6 of 8 failed on assertions (:46,:55,:63,:72,:77,:95). Green: 8/8.test/deadcode-report.test.js: neither the job nor any step setscontinue-on-error.shell: bashis kept soteedoes not hide knip's exit. There is no global switch and noignoreIssues,ignoreis still onlypublic/**, andpreprocessoris./scripts/knip-preprocessor.js. A new test checks that neither the task nor the CI step passes--preprocessor,--no-exit-code,--max-issues,--includeor--exclude. Red on base 944791a at:59(continue-on-errortrue). Red against the previous head'sknip.jsonat:74(ignoreIssuespresent). Green: 6/6.test/build-workflow.test.js17/17,test/check-docs.test.js99/99,module-layout7/7,eslint-main-scope3/3,packaged-script-paths1/1,check-fast17/17 (Node 22).eslinton the changed JS,node scripts/check-docs.js --validate,node scripts/check-doc-refs.js(0 failures),git diff --checkandSKIP_TESTS=1 task check:fastall pass.--exclude binaries, the local run also reportsknipas an unlisted binary inTaskfile.yamlandtest.yml. That comes from the local environment: the sharednode_moduleshas no knip installed. CI installs it, and the main CI report did not show these findings.Not verified
deadcodein the repository ruleset is unchanged; making it required is the maintainer's call.no-changelog: tooling only, nothing users see.